Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-724.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Correctly set dependency between spotlessApply and baselineUpdateConfig
to prevent a race
links:
- https://github.com/palantir/gradle-baseline/pull/724
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ public void apply(Project project) {

// necessary because SpotlessPlugin creates tasks in an afterEvaluate block
Task formatTask = project.task("format");
if (eclipseFormattingEnabled(project) && !Files.exists(eclipseXml)) {
formatTask.dependsOn(project.getTasks().findByPath(":baselineUpdateConfig"));
}
project.afterEvaluate(p -> {
Task spotlessJava = project.getTasks().getByName("spotlessJava");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was also another slight bug, where we referenced the wrong spotless task. Turns out that the task doing all of the work is spotlessJava and that it uses the presence of other tasks in the task graph to determine how to behave https://github.com/diffplug/spotless/blob/master/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java#L99

Task spotlessApply = project.getTasks().getByName("spotlessApply");
if (eclipseFormattingEnabled(project) && !Files.exists(eclipseXml)) {
spotlessJava.dependsOn(project.getTasks().findByPath(":baselineUpdateConfig"));
}
formatTask.dependsOn(spotlessApply);
project.getTasks().withType(JavaCompile.class).configureEach(spotlessApply::mustRunAfter);
project.getTasks().withType(JavaCompile.class).configureEach(spotlessJava::mustRunAfter);
});
});
}
Expand Down