From 9942f15433f068c3862cbe9ac733153d1f2c9be9 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 10:04:32 -0700 Subject: [PATCH 01/12] WIP --- .../groovy/nullaway.jacoco-conventions.gradle | 2 +- gradle/dependencies.gradle | 3 +- nullaway/build.gradle | 38 ++++++++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle b/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle index 1c7c97c620..987831f574 100644 --- a/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle +++ b/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle @@ -20,7 +20,7 @@ plugins { } jacoco { - toolVersion = "0.8.7" + toolVersion = "0.8.10" } // Do not generate reports for individual projects diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index c1c264e6b0..1e9bb1c99a 100755 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -113,8 +113,7 @@ def test = [ springBeans : "org.springframework:spring-beans:5.3.7", springContext : "org.springframework:spring-context:5.3.7", grpcCore : "io.grpc:grpc-core:1.15.1", // Should upgrade, but this matches our guava version - mockito : "org.mockito:mockito-core:4.6.1", - mockitoInline : "org.mockito:mockito-inline:4.6.1", + mockito : "org.mockito:mockito-core:5.5.0", javaxAnnotationApi : "javax.annotation:javax.annotation-api:1.3.2", assertJ : "org.assertj:assertj-core:3.23.1", ] diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 5b6346f4a9..f76cc1803b 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -62,7 +62,6 @@ dependencies { testImplementation deps.test.grpcCore testImplementation project(":test-java-lib-lombok") testImplementation deps.test.mockito - testImplementation deps.test.mockitoInline testImplementation deps.test.javaxAnnotationApi testImplementation deps.test.assertJ } @@ -141,8 +140,45 @@ def jdk8Test = tasks.register("testJdk8", Test) { jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}" } +// Create a task to test on JDK 21 +def jdk21Test = tasks.register("testJdk21", Test) { + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + } + + description = "Runs the test suite on JDK 21" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + maxHeapSize = "1024m" + // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer + jvmArgs += [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + // Accessed by Lombok tests + "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + ] + filter { + // These tests do not yet pass on JDK 21 + // TODO open task to track this + excludeTestsMatching "com.uber.nullaway.NullAwayJSpecifyGenericsTests" + } +} + tasks.named('check').configure { dependsOn(jdk8Test) + dependsOn(jdk21Test) } // Create a task to build NullAway with NullAway checking enabled From 740bcd42fb59d8590a93886c63b8321963254fdc Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 10:13:16 -0700 Subject: [PATCH 02/12] tweak comment --- nullaway/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nullaway/build.gradle b/nullaway/build.gradle index f76cc1803b..387dce7f3f 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -170,7 +170,7 @@ def jdk21Test = tasks.register("testJdk21", Test) { "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", ] filter { - // These tests do not yet pass on JDK 21 + // JSpecify Generics tests do not yet pass on JDK 21 // TODO open task to track this excludeTestsMatching "com.uber.nullaway.NullAwayJSpecifyGenericsTests" } From 09d7eaba8c00bca6bdd52b0d1d5dcef22f022a5c Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 10:23:02 -0700 Subject: [PATCH 03/12] tweaks --- .github/workflows/continuous-integration.yml | 5 +++++ nullaway/build.gradle | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c642b22c03..acf0d55842 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -36,6 +36,11 @@ jobs: steps: - name: Check out NullAway sources uses: actions/checkout@v3 + - name: 'Set up JDK 21 so it is available' + uses: actions/setup-java@v3 + with: + java-version: '21-ea' + distribution: 'temurin' - name: 'Set up JDK 17 on Windows' uses: actions/setup-java@v3 with: diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 387dce7f3f..7ac3d90e06 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -142,6 +142,10 @@ def jdk8Test = tasks.register("testJdk8", Test) { // Create a task to test on JDK 21 def jdk21Test = tasks.register("testJdk21", Test) { + onlyIf { + // Only test on JDK 21 when using the latest Error Prone version + deps.versions.errorProneApi == deps.versions.errorProneLatest + } javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(21) } From e4a475bfb1bfe9060ae58789724d14f302640bfc Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 10:34:12 -0700 Subject: [PATCH 04/12] exclude a couple tests on JDK 8 --- nullaway/build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 7ac3d90e06..1667f8568e 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -138,6 +138,12 @@ def jdk8Test = tasks.register("testJdk8", Test) { classpath = testTask.classpath testClassesDirs = testTask.testClassesDirs jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}" + filter { + // tests cannot run on JDK 8 since Mockito version no longer supports it + excludeTestsMatching "com.uber.nullaway.NullAwaySerializationTest.initializationError" + excludeTestsMatching "com.uber.nullaway.handlers.contract.ContractUtilsTest.getEmptyAntecedent" + } + } // Create a task to test on JDK 21 From 0e9e12c44cebbda1e3f6c3f4262afc12186871ea Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 10:37:45 -0700 Subject: [PATCH 05/12] formatting --- nullaway/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 1667f8568e..9120901981 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -143,7 +143,6 @@ def jdk8Test = tasks.register("testJdk8", Test) { excludeTestsMatching "com.uber.nullaway.NullAwaySerializationTest.initializationError" excludeTestsMatching "com.uber.nullaway.handlers.contract.ContractUtilsTest.getEmptyAntecedent" } - } // Create a task to test on JDK 21 From f6aebf9c5df6fce7745246a4735ae66c16b19526 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 10:57:07 -0700 Subject: [PATCH 06/12] add link to issue --- nullaway/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 9120901981..fef66b0877 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -180,7 +180,7 @@ def jdk21Test = tasks.register("testJdk21", Test) { ] filter { // JSpecify Generics tests do not yet pass on JDK 21 - // TODO open task to track this + // See https://github.com/uber/NullAway/issues/827 excludeTestsMatching "com.uber.nullaway.NullAwayJSpecifyGenericsTests" } } From 5dfa5186ebe995f42998e8bb8a92e4e0fe8aa697 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 13:20:12 -0700 Subject: [PATCH 07/12] test more modules on JDK 21 --- annotations/build.gradle | 39 +++++++++++++++++ guava-recent-unit-tests/build.gradle | 36 ++++++++++++++++ jar-infer/jar-infer-lib/build.gradle | 40 ++++++++++++++++++ .../nullaway-integration-test/build.gradle | 39 +++++++++++++++++ jdk17-unit-tests/build.gradle | 42 +++++++++++++++++++ 5 files changed, 196 insertions(+) diff --git a/annotations/build.gradle b/annotations/build.gradle index 5e06f02c25..e6067cf819 100644 --- a/annotations/build.gradle +++ b/annotations/build.gradle @@ -42,4 +42,43 @@ test { ] } +// Create a task to test on JDK 21 +def jdk21Test = tasks.register("testJdk21", Test) { + onlyIf { + // Only test on JDK 21 when using the latest Error Prone version + deps.versions.errorProneApi == deps.versions.errorProneLatest + } + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + } + + description = "Runs the test suite on JDK 21" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + maxHeapSize = "1024m" + // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer + jvmArgs += [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + // Accessed by Lombok tests + "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + ] +} + +tasks.named('check').configure { + dependsOn(jdk21Test) +} + apply plugin: 'com.vanniktech.maven.publish' diff --git a/guava-recent-unit-tests/build.gradle b/guava-recent-unit-tests/build.gradle index b81bd0f8df..52d71b3d54 100644 --- a/guava-recent-unit-tests/build.gradle +++ b/guava-recent-unit-tests/build.gradle @@ -71,6 +71,42 @@ def jdk8Test = tasks.register("testJdk8", Test) { jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}" } +// Create a task to test on JDK 21 +def jdk21Test = tasks.register("testJdk21", Test) { + onlyIf { + // Only test on JDK 21 when using the latest Error Prone version + deps.versions.errorProneApi == deps.versions.errorProneLatest + } + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + } + + description = "Runs the test suite on JDK 21" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + maxHeapSize = "1024m" + // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer + jvmArgs += [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + // Accessed by Lombok tests + "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + ] +} + tasks.named('check').configure { dependsOn(jdk8Test) + dependsOn(jdk21Test) } diff --git a/jar-infer/jar-infer-lib/build.gradle b/jar-infer/jar-infer-lib/build.gradle index ec221573c2..6bf76605e0 100644 --- a/jar-infer/jar-infer-lib/build.gradle +++ b/jar-infer/jar-infer-lib/build.gradle @@ -67,6 +67,46 @@ test { dependsOn ':jar-infer:test-android-lib-jarinfer:bundleReleaseAar' } +// Create a task to test on JDK 21 +def jdk21Test = tasks.register("testJdk21", Test) { + onlyIf { + // Only test on JDK 21 when using the latest Error Prone version + deps.versions.errorProneApi == deps.versions.errorProneLatest + } + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + } + + description = "Runs the test suite on JDK 21" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + maxHeapSize = "1024m" + // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer + jvmArgs += [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + // Accessed by Lombok tests + "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + ] +} + +// Tests do not pass yet on JDK 21, so do not require it +//tasks.named('check').configure { +// dependsOn(jdk21Test) +//} + tasks.withType(JavaCompile).configureEach { options.compilerArgs += "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED" } diff --git a/jar-infer/nullaway-integration-test/build.gradle b/jar-infer/nullaway-integration-test/build.gradle index 03da29711a..e04fb18026 100644 --- a/jar-infer/nullaway-integration-test/build.gradle +++ b/jar-infer/nullaway-integration-test/build.gradle @@ -44,3 +44,42 @@ test { "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", ] } + +// Create a task to test on JDK 21 +def jdk21Test = tasks.register("testJdk21", Test) { + onlyIf { + // Only test on JDK 21 when using the latest Error Prone version + deps.versions.errorProneApi == deps.versions.errorProneLatest + } + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + } + + description = "Runs the test suite on JDK 21" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + maxHeapSize = "1024m" + // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer + jvmArgs += [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + // Accessed by Lombok tests + "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + ] +} + +tasks.named('check').configure { + dependsOn(jdk21Test) +} diff --git a/jdk17-unit-tests/build.gradle b/jdk17-unit-tests/build.gradle index 8f37181bff..080adaf01e 100644 --- a/jdk17-unit-tests/build.gradle +++ b/jdk17-unit-tests/build.gradle @@ -62,3 +62,45 @@ test { "-Dtest.module.path=${configurations.testModulePath.asPath}" ] } + +// Create a task to test on JDK 21 +def jdk21Test = tasks.register("testJdk21", Test) { + onlyIf { + // Only test on JDK 21 when using the latest Error Prone version + deps.versions.errorProneApi == deps.versions.errorProneLatest + } + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + } + + description = "Runs the test suite on JDK 21" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + maxHeapSize = "1024m" + // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer + jvmArgs += [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + // Accessed by Lombok tests + "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + // Expose a module path for tests as a JVM property. + // Used by com.uber.nullaway.jdk17.NullAwayModuleInfoTests + "-Dtest.module.path=${configurations.testModulePath.asPath}" + ] +} + +tasks.named('check').configure { + dependsOn(jdk21Test) +} From a1fd62c8f396c8bd4be537c7233db2ee3be13300 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 21:46:40 -0700 Subject: [PATCH 08/12] various build script cleanups --- annotations/build.gradle | 60 +-------- .../groovy/nullaway.jacoco-conventions.gradle | 62 ---------- .../nullaway.java-test-conventions.gradle | 116 ++++++++++++++++++ guava-recent-unit-tests/build.gradle | 58 +-------- jar-infer/jar-infer-lib/build.gradle | 58 +-------- .../nullaway-integration-test/build.gradle | 57 +-------- jdk17-unit-tests/build.gradle | 48 +------- jmh/build.gradle | 26 ++-- nullaway/build.gradle | 61 ++------- 9 files changed, 145 insertions(+), 401 deletions(-) delete mode 100644 buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle create mode 100644 buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle diff --git a/annotations/build.gradle b/annotations/build.gradle index e6067cf819..74026510c0 100644 --- a/annotations/build.gradle +++ b/annotations/build.gradle @@ -17,68 +17,14 @@ import net.ltgt.gradle.errorprone.CheckSeverity plugins { id 'java-library' - id 'nullaway.jacoco-conventions' + id 'nullaway.java-test-conventions' } dependencies { } -test { - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] -} - -// Create a task to test on JDK 21 -def jdk21Test = tasks.register("testJdk21", Test) { - onlyIf { - // Only test on JDK 21 when using the latest Error Prone version - deps.versions.errorProneApi == deps.versions.errorProneLatest - } - javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(21) - } - - description = "Runs the test suite on JDK 21" - group = LifecycleBasePlugin.VERIFICATION_GROUP - - // Copy inputs from normal Test task. - def testTask = tasks.getByName("test") - classpath = testTask.classpath - testClassesDirs = testTask.testClassesDirs - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] -} - -tasks.named('check').configure { - dependsOn(jdk21Test) +project.tasks.named('check').configure { + dependsOn tasks.getByName('testJdk21') } apply plugin: 'com.vanniktech.maven.publish' diff --git a/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle b/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle deleted file mode 100644 index 987831f574..0000000000 --- a/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2021. Uber Technologies - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Mostly taken from official Gradle sample: https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html -plugins { - id 'jacoco' -} - -jacoco { - toolVersion = "0.8.10" -} - -// Do not generate reports for individual projects -tasks.named("jacocoTestReport") { - enabled = false -} - -// Share sources folder with other projects for aggregated JaCoCo reports -configurations.create('transitiveSourcesElements') { - visible = false - canBeResolved = false - canBeConsumed = true - extendsFrom(configurations.implementation) - attributes { - attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) - attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) - attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'source-folders')) - } - sourceSets.main.java.srcDirs.forEach { - outgoing.artifact(it) - } -} - -// Share the coverage data to be aggregated for the whole product -configurations.create('coverageDataElements') { - visible = false - canBeResolved = false - canBeConsumed = true - extendsFrom(configurations.implementation) - attributes { - attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) - attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) - attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'jacoco-coverage-data')) - } - // This will cause the test task to run if the coverage data is requested by the aggregation task - outgoing.artifact(tasks.named("test").map { task -> - task.extensions.getByType(JacocoTaskExtension).destinationFile - }) -} diff --git a/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle b/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle new file mode 100644 index 0000000000..4859ba523a --- /dev/null +++ b/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2021. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Mostly taken from official Gradle sample: https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html +plugins { + id 'jacoco' +} + +jacoco { + toolVersion = "0.8.10" +} + +// Do not generate reports for individual projects +tasks.named("jacocoTestReport") { + enabled = false +} + +// Share sources folder with other projects for aggregated JaCoCo reports +configurations.create('transitiveSourcesElements') { + visible = false + canBeResolved = false + canBeConsumed = true + extendsFrom(configurations.implementation) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'source-folders')) + } + sourceSets.main.java.srcDirs.forEach { + outgoing.artifact(it) + } +} + +// Share the coverage data to be aggregated for the whole product +configurations.create('coverageDataElements') { + visible = false + canBeResolved = false + canBeConsumed = true + extendsFrom(configurations.implementation) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'jacoco-coverage-data')) + } + // This will cause the test task to run if the coverage data is requested by the aggregation task + outgoing.artifact(tasks.named("test").map { task -> + task.extensions.getByType(JacocoTaskExtension).destinationFile + }) +} + +test { + maxHeapSize = "1024m" + // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer + jvmArgs += [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + // Accessed by Lombok tests + "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + ] +} + +// Create a task to test on JDK 21 +tasks.register("testJdk21", Test) { + onlyIf { + // Only test on JDK 21 when using the latest Error Prone version + deps.versions.errorProneApi == deps.versions.errorProneLatest + } + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + } + + description = "Runs the test suite on JDK 21" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + maxHeapSize = "1024m" + // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer + jvmArgs += [ + "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + // Accessed by Lombok tests + "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + ] +} diff --git a/guava-recent-unit-tests/build.gradle b/guava-recent-unit-tests/build.gradle index 52d71b3d54..e38a321a88 100644 --- a/guava-recent-unit-tests/build.gradle +++ b/guava-recent-unit-tests/build.gradle @@ -15,7 +15,7 @@ */ plugins { id 'java-library' - id 'nullaway.jacoco-conventions' + id 'nullaway.java-test-conventions' } // We need this separate build target to test newer versions of Guava @@ -31,25 +31,6 @@ dependencies { testImplementation "com.google.guava:guava:31.1-jre" } -test { - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] -} - // Create a task to test on JDK 8 def jdk8Test = tasks.register("testJdk8", Test) { onlyIf { @@ -71,42 +52,7 @@ def jdk8Test = tasks.register("testJdk8", Test) { jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}" } -// Create a task to test on JDK 21 -def jdk21Test = tasks.register("testJdk21", Test) { - onlyIf { - // Only test on JDK 21 when using the latest Error Prone version - deps.versions.errorProneApi == deps.versions.errorProneLatest - } - javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(21) - } - - description = "Runs the test suite on JDK 21" - group = LifecycleBasePlugin.VERIFICATION_GROUP - - // Copy inputs from normal Test task. - def testTask = tasks.getByName("test") - classpath = testTask.classpath - testClassesDirs = testTask.testClassesDirs - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] -} - tasks.named('check').configure { dependsOn(jdk8Test) - dependsOn(jdk21Test) + dependsOn tasks.getByName('testJdk21') } diff --git a/jar-infer/jar-infer-lib/build.gradle b/jar-infer/jar-infer-lib/build.gradle index 6bf76605e0..d0d9056278 100644 --- a/jar-infer/jar-infer-lib/build.gradle +++ b/jar-infer/jar-infer-lib/build.gradle @@ -15,7 +15,7 @@ */ plugins { id "java-library" - id 'nullaway.jacoco-conventions' + id 'nullaway.java-test-conventions' } // JarInfer requires JDK 11+, due to its dependence on WALA @@ -48,64 +48,10 @@ dependencies { } test { - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] dependsOn ':jar-infer:test-android-lib-jarinfer:bundleReleaseAar' } -// Create a task to test on JDK 21 -def jdk21Test = tasks.register("testJdk21", Test) { - onlyIf { - // Only test on JDK 21 when using the latest Error Prone version - deps.versions.errorProneApi == deps.versions.errorProneLatest - } - javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(21) - } - - description = "Runs the test suite on JDK 21" - group = LifecycleBasePlugin.VERIFICATION_GROUP - - // Copy inputs from normal Test task. - def testTask = tasks.getByName("test") - classpath = testTask.classpath - testClassesDirs = testTask.testClassesDirs - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] -} - -// Tests do not pass yet on JDK 21, so do not require it -//tasks.named('check').configure { -// dependsOn(jdk21Test) -//} +// NOTE: tests do not pass yet on JDK 21, so we do not add a dependence from check to the testJdk21 test tasks.withType(JavaCompile).configureEach { options.compilerArgs += "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED" diff --git a/jar-infer/nullaway-integration-test/build.gradle b/jar-infer/nullaway-integration-test/build.gradle index e04fb18026..bc51da98b0 100644 --- a/jar-infer/nullaway-integration-test/build.gradle +++ b/jar-infer/nullaway-integration-test/build.gradle @@ -15,7 +15,7 @@ */ plugins { id "java-library" - id "nullaway.jacoco-conventions" + id "nullaway.java-test-conventions" } dependencies { @@ -27,59 +27,6 @@ dependencies { testImplementation project(":jar-infer:test-java-lib-jarinfer") } - -test { - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - ] -} - -// Create a task to test on JDK 21 -def jdk21Test = tasks.register("testJdk21", Test) { - onlyIf { - // Only test on JDK 21 when using the latest Error Prone version - deps.versions.errorProneApi == deps.versions.errorProneLatest - } - javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(21) - } - - description = "Runs the test suite on JDK 21" - group = LifecycleBasePlugin.VERIFICATION_GROUP - - // Copy inputs from normal Test task. - def testTask = tasks.getByName("test") - classpath = testTask.classpath - testClassesDirs = testTask.testClassesDirs - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] -} - tasks.named('check').configure { - dependsOn(jdk21Test) + dependsOn tasks.getByName('testJdk21') } diff --git a/jdk17-unit-tests/build.gradle b/jdk17-unit-tests/build.gradle index 080adaf01e..98ec9a307e 100644 --- a/jdk17-unit-tests/build.gradle +++ b/jdk17-unit-tests/build.gradle @@ -15,7 +15,7 @@ */ plugins { id 'java-library' - id 'nullaway.jacoco-conventions' + id 'nullaway.java-test-conventions' } // Use JDK 17 for this module, via a toolchain @@ -44,57 +44,15 @@ dependencies { } test { - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", // Expose a module path for tests as a JVM property. // Used by com.uber.nullaway.jdk17.NullAwayModuleInfoTests "-Dtest.module.path=${configurations.testModulePath.asPath}" ] } -// Create a task to test on JDK 21 -def jdk21Test = tasks.register("testJdk21", Test) { - onlyIf { - // Only test on JDK 21 when using the latest Error Prone version - deps.versions.errorProneApi == deps.versions.errorProneLatest - } - javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(21) - } - - description = "Runs the test suite on JDK 21" - group = LifecycleBasePlugin.VERIFICATION_GROUP - - // Copy inputs from normal Test task. - def testTask = tasks.getByName("test") - classpath = testTask.classpath - testClassesDirs = testTask.testClassesDirs - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer +tasks.getByName('testJdk21').configure { jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", // Expose a module path for tests as a JVM property. // Used by com.uber.nullaway.jdk17.NullAwayModuleInfoTests "-Dtest.module.path=${configurations.testModulePath.asPath}" @@ -102,5 +60,5 @@ def jdk21Test = tasks.register("testJdk21", Test) { } tasks.named('check').configure { - dependsOn(jdk21Test) + dependsOn tasks.getByName('testJdk21') } diff --git a/jmh/build.gradle b/jmh/build.gradle index 03752ffbbc..3629a5506c 100644 --- a/jmh/build.gradle +++ b/jmh/build.gradle @@ -15,7 +15,7 @@ */ plugins { id 'java-library' - id 'nullaway.jacoco-conventions' + id 'nullaway.java-test-conventions' id 'me.champeau.jmh' } @@ -128,21 +128,15 @@ jmh { // includes = ['DFlowMicro'] } -// don't run test task on pre-JDK-11 VMs tasks.named('test') { // pass the extra JVM args so we can compile benchmarks in unit tests - jvmArgs extraJVMArgs - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - ] + jvmArgs += extraJVMArgs +} + +tasks.getByName('testJdk21').configure { + jvmArgs += extraJVMArgs +} + +tasks.named('check').configure { + dependsOn tasks.getByName('testJdk21') } diff --git a/nullaway/build.gradle b/nullaway/build.gradle index fef66b0877..6cea410b84 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -17,7 +17,7 @@ import net.ltgt.gradle.errorprone.CheckSeverity plugins { id 'java-library' - id 'nullaway.jacoco-conventions' + id 'nullaway.java-test-conventions' } configurations { @@ -72,22 +72,6 @@ javadoc { test { - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] if (deps.versions.errorProneApi == "2.4.0" && JavaVersion.current() >= JavaVersion.VERSION_17) { // This test does not pass on JDK 17 with Error Prone 2.4.0 due to a Mockito incompatibility. Skip it (the // test passes with more recent Error Prone versions on JDK 17) @@ -145,39 +129,11 @@ def jdk8Test = tasks.register("testJdk8", Test) { } } -// Create a task to test on JDK 21 -def jdk21Test = tasks.register("testJdk21", Test) { - onlyIf { - // Only test on JDK 21 when using the latest Error Prone version - deps.versions.errorProneApi == deps.versions.errorProneLatest - } - javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(21) - } - - description = "Runs the test suite on JDK 21" - group = LifecycleBasePlugin.VERIFICATION_GROUP +tasks.named('check').configure { + dependsOn(jdk8Test) +} - // Copy inputs from normal Test task. - def testTask = tasks.getByName("test") - classpath = testTask.classpath - testClassesDirs = testTask.testClassesDirs - maxHeapSize = "1024m" - // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer - jvmArgs += [ - "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", - // Accessed by Lombok tests - "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", - ] +tasks.named('testJdk21', Test).configure { filter { // JSpecify Generics tests do not yet pass on JDK 21 // See https://github.com/uber/NullAway/issues/827 @@ -185,11 +141,6 @@ def jdk21Test = tasks.register("testJdk21", Test) { } } -tasks.named('check').configure { - dependsOn(jdk8Test) - dependsOn(jdk21Test) -} - // Create a task to build NullAway with NullAway checking enabled tasks.register('buildWithNullAway', JavaCompile) { onlyIf { @@ -227,4 +178,6 @@ tasks.register('buildWithNullAway', JavaCompile) { project.tasks.named('check').configure { dependsOn 'buildWithNullAway' + dependsOn testJdk8 + dependsOn tasks.getByName('testJdk21') } From 11f24858a1c469858f9e48cdaee69254f67bd328 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Sep 2023 21:47:24 -0700 Subject: [PATCH 09/12] small tweak --- annotations/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annotations/build.gradle b/annotations/build.gradle index 74026510c0..637bb89f67 100644 --- a/annotations/build.gradle +++ b/annotations/build.gradle @@ -23,7 +23,7 @@ plugins { dependencies { } -project.tasks.named('check').configure { +tasks.named('check').configure { dependsOn tasks.getByName('testJdk21') } From 034aafb626344365904c90f2eab09f2902d678cf Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 5 Sep 2023 08:43:39 -0700 Subject: [PATCH 10/12] cleanup --- annotations/build.gradle | 4 ---- .../src/main/groovy/nullaway.java-test-conventions.gradle | 6 +++++- guava-recent-unit-tests/build.gradle | 1 - jar-infer/jar-infer-lib/build.gradle | 6 +++++- jar-infer/nullaway-integration-test/build.gradle | 4 ---- jdk17-unit-tests/build.gradle | 4 ---- jmh/build.gradle | 4 ---- nullaway/build.gradle | 1 - 8 files changed, 10 insertions(+), 20 deletions(-) diff --git a/annotations/build.gradle b/annotations/build.gradle index 637bb89f67..ebb8ff5ca6 100644 --- a/annotations/build.gradle +++ b/annotations/build.gradle @@ -23,8 +23,4 @@ plugins { dependencies { } -tasks.named('check').configure { - dependsOn tasks.getByName('testJdk21') -} - apply plugin: 'com.vanniktech.maven.publish' diff --git a/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle b/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle index 4859ba523a..1052566319 100644 --- a/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle +++ b/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle @@ -81,7 +81,7 @@ test { } // Create a task to test on JDK 21 -tasks.register("testJdk21", Test) { +def testJdk21 = tasks.register("testJdk21", Test) { onlyIf { // Only test on JDK 21 when using the latest Error Prone version deps.versions.errorProneApi == deps.versions.errorProneLatest @@ -114,3 +114,7 @@ tasks.register("testJdk21", Test) { "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", ] } + +tasks.named('check').configure { + dependsOn testJdk21 +} diff --git a/guava-recent-unit-tests/build.gradle b/guava-recent-unit-tests/build.gradle index e38a321a88..4d78ac52a3 100644 --- a/guava-recent-unit-tests/build.gradle +++ b/guava-recent-unit-tests/build.gradle @@ -54,5 +54,4 @@ def jdk8Test = tasks.register("testJdk8", Test) { tasks.named('check').configure { dependsOn(jdk8Test) - dependsOn tasks.getByName('testJdk21') } diff --git a/jar-infer/jar-infer-lib/build.gradle b/jar-infer/jar-infer-lib/build.gradle index d0d9056278..2ae8bea7a8 100644 --- a/jar-infer/jar-infer-lib/build.gradle +++ b/jar-infer/jar-infer-lib/build.gradle @@ -51,7 +51,11 @@ test { dependsOn ':jar-infer:test-android-lib-jarinfer:bundleReleaseAar' } -// NOTE: tests do not pass yet on JDK 21, so we do not add a dependence from check to the testJdk21 test +tasks.named('testJdk21', Test).configure { + // Tests fail since WALA does not yet support JDK 21; see https://github.com/uber/NullAway/issues/829 + // So, disable them + onlyIf { false } +} tasks.withType(JavaCompile).configureEach { options.compilerArgs += "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED" diff --git a/jar-infer/nullaway-integration-test/build.gradle b/jar-infer/nullaway-integration-test/build.gradle index bc51da98b0..94a880861a 100644 --- a/jar-infer/nullaway-integration-test/build.gradle +++ b/jar-infer/nullaway-integration-test/build.gradle @@ -26,7 +26,3 @@ dependencies { testImplementation project(":nullaway") testImplementation project(":jar-infer:test-java-lib-jarinfer") } - -tasks.named('check').configure { - dependsOn tasks.getByName('testJdk21') -} diff --git a/jdk17-unit-tests/build.gradle b/jdk17-unit-tests/build.gradle index 98ec9a307e..1c9f7f908d 100644 --- a/jdk17-unit-tests/build.gradle +++ b/jdk17-unit-tests/build.gradle @@ -58,7 +58,3 @@ tasks.getByName('testJdk21').configure { "-Dtest.module.path=${configurations.testModulePath.asPath}" ] } - -tasks.named('check').configure { - dependsOn tasks.getByName('testJdk21') -} diff --git a/jmh/build.gradle b/jmh/build.gradle index 3629a5506c..68e3c58446 100644 --- a/jmh/build.gradle +++ b/jmh/build.gradle @@ -136,7 +136,3 @@ tasks.named('test') { tasks.getByName('testJdk21').configure { jvmArgs += extraJVMArgs } - -tasks.named('check').configure { - dependsOn tasks.getByName('testJdk21') -} diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 6cea410b84..92b864c236 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -179,5 +179,4 @@ tasks.register('buildWithNullAway', JavaCompile) { project.tasks.named('check').configure { dependsOn 'buildWithNullAway' dependsOn testJdk8 - dependsOn tasks.getByName('testJdk21') } From 7e1a2b41c101fe1565e4e06cd866bf6920c8417c Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 5 Sep 2023 08:48:19 -0700 Subject: [PATCH 11/12] remove unneeded line --- nullaway/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 92b864c236..026a89094a 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -178,5 +178,4 @@ tasks.register('buildWithNullAway', JavaCompile) { project.tasks.named('check').configure { dependsOn 'buildWithNullAway' - dependsOn testJdk8 } From 73fa73a19ac59a99dd389d2e7541dbed095bb464 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 5 Sep 2023 12:10:18 -0700 Subject: [PATCH 12/12] Update copyright year --- buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle b/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle index 1052566319..07f8f2690e 100644 --- a/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle +++ b/buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021. Uber Technologies + * Copyright (C) 2023. Uber Technologies * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.