From 1bd74e702b3aa1e5294917876717c5fb8ca11156 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Mon, 19 Sep 2022 10:29:07 -0400 Subject: [PATCH 1/3] lazily configure NullAway dependencies --- .../baseline/plugins/BaselineNullAway.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineNullAway.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineNullAway.java index a0ef9c5f2..08d42b1a9 100644 --- a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineNullAway.java +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineNullAway.java @@ -22,9 +22,11 @@ import org.gradle.api.Action; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; import org.gradle.api.plugins.ExtensionAware; +import org.gradle.api.specs.Spec; import org.gradle.api.tasks.compile.JavaCompile; public final class BaselineNullAway implements Plugin { @@ -50,7 +52,20 @@ private void applyToProject(Project project) { + "beware this compromises build reproducibility"); return "latest.release"; }); - project.getDependencies().add("errorprone", "com.palantir.baseline:baseline-null-away:" + version); + project.getConfigurations() + .matching(new Spec() { + @Override + public boolean isSatisfiedBy(Configuration config) { + return "errorprone".equals(config.getName()); + } + }) + .configureEach(new Action() { + @Override + public void execute(Configuration _files) { + project.getDependencies() + .add("errorprone", "com.palantir.baseline:baseline-null-away:" + version); + } + }); configureErrorProneOptions(project, new Action() { @Override public void execute(ErrorProneOptions options) { @@ -60,11 +75,18 @@ public void execute(ErrorProneOptions options) { }); } - private static void configureErrorProneOptions(Project project, Action action) { - project.getTasks().withType(JavaCompile.class).configureEach(new Action() { + private static void configureErrorProneOptions(Project proj, Action action) { + proj.afterEvaluate(new Action() { @Override - public void execute(JavaCompile javaCompile) { - ((ExtensionAware) javaCompile.getOptions()).getExtensions().configure(ErrorProneOptions.class, action); + public void execute(Project project) { + project.getTasks().withType(JavaCompile.class).configureEach(new Action() { + @Override + public void execute(JavaCompile javaCompile) { + ((ExtensionAware) javaCompile.getOptions()) + .getExtensions() + .configure(ErrorProneOptions.class, action); + } + }); } }); } From e8349c36ec35362a20286c150cf71258e2817517 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Mon, 19 Sep 2022 12:12:44 -0400 Subject: [PATCH 2/3] repro test --- .../BaselineNullAwayIntegrationTest.groovy | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineNullAwayIntegrationTest.groovy b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineNullAwayIntegrationTest.groovy index 6fd8a9a0f..2c023ccad 100644 --- a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineNullAwayIntegrationTest.groovy +++ b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineNullAwayIntegrationTest.groovy @@ -16,20 +16,16 @@ package com.palantir.baseline +import nebula.test.IntegrationSpec +import nebula.test.functional.ExecutionResult -import org.gradle.testkit.runner.BuildResult -import org.gradle.testkit.runner.TaskOutcome -import spock.lang.Unroll - -class BaselineNullAwayIntegrationTest extends AbstractPluginTest { +class BaselineNullAwayIntegrationTest extends IntegrationSpec { def standardBuildFile = ''' - plugins { - id 'java' - id 'com.palantir.baseline-error-prone' - id 'com.palantir.baseline-null-away' - id 'com.palantir.baseline-java-versions' - } + apply plugin: 'com.palantir.baseline-java-versions' + apply plugin: 'com.palantir.baseline-null-away' + apply plugin: 'com.palantir.baseline-error-prone' + apply plugin: 'java' repositories { mavenLocal() mavenCentral() @@ -37,8 +33,15 @@ class BaselineNullAwayIntegrationTest extends AbstractPluginTest { javaVersions { libraryTarget = 17 } - tasks.withType(JavaCompile).configureEach { - options.compilerArgs += ['-Werror'] + allprojects { + afterEvaluate { + plugins.withId('net.ltgt.errorprone', { + tasks.withType(JavaCompile).configureEach({ + options.errorprone.excludedPaths = null + options.compilerArgs += ['-Werror'] + }) + }) + } } '''.stripIndent() @@ -62,47 +65,43 @@ class BaselineNullAwayIntegrationTest extends AbstractPluginTest { buildFile << standardBuildFile then: - with('compileJava', '--info').build() + runTasksSuccessfully('compileJava', '--info') } def 'compileJava fails when null-away finds errors'() { when: buildFile << standardBuildFile - file('src/main/java/com/palantir/test/Test.java') << invalidJavaFile + writeJavaSourceFile(invalidJavaFile) then: - BuildResult result = with('compileJava').buildAndFail() - result.task(":compileJava").outcome == TaskOutcome.FAILED - result.output.contains("[NullAway] dereferenced expression throwable.getMessage() is @Nullable") + ExecutionResult result = runTasksWithFailure('compileJava') + result.standardError.contains("[NullAway] dereferenced expression throwable.getMessage() is @Nullable") } def 'compileJava succeeds when null-away finds no errors'() { when: buildFile << standardBuildFile - file('src/main/java/com/palantir/test/Test.java') << validJavaFile + writeJavaSourceFile(validJavaFile) then: - BuildResult result = with('compileJava').build() - result.task(":compileJava").outcome == TaskOutcome.SUCCESS + runTasksSuccessfully('compileJava') } def 'compileJava succeeds when null-away finds no errors on jdk15'() { when: buildFile << standardBuildFile.replace('libraryTarget = 17', 'libraryTarget = 15') - file('src/main/java/com/palantir/test/Test.java') << validJavaFile + writeJavaSourceFile(validJavaFile) then: - BuildResult result = with('compileJava').build() - result.task(":compileJava").outcome == TaskOutcome.SUCCESS + runTasksSuccessfully('compileJava') } def 'compileJava succeeds when null-away finds no errors on jdk11'() { when: buildFile << standardBuildFile.replace('libraryTarget = 17', 'libraryTarget = 11') - file('src/main/java/com/palantir/test/Test.java') << validJavaFile + writeJavaSourceFile(validJavaFile) then: - BuildResult result = with('compileJava').build() - result.task(":compileJava").outcome == TaskOutcome.SUCCESS + runTasksSuccessfully('compileJava') } } From de63e29af46e6b15f52bcae58cc606eaa44f6c68 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Mon, 19 Sep 2022 16:13:59 +0000 Subject: [PATCH 3/3] Add generated changelog entries --- changelog/@unreleased/pr-2393.v2.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/@unreleased/pr-2393.v2.yml diff --git a/changelog/@unreleased/pr-2393.v2.yml b/changelog/@unreleased/pr-2393.v2.yml new file mode 100644 index 000000000..869b8f706 --- /dev/null +++ b/changelog/@unreleased/pr-2393.v2.yml @@ -0,0 +1,6 @@ +type: fix +fix: + description: lazily configure NullAway dependencies to successfully apply NullAway + without ordering issues + links: + - https://github.com/palantir/gradle-baseline/pull/2393