diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9ffc08a106..7b3ba902bd 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -21,16 +21,16 @@ jobs: epVersion: 2.4.0 - os: macos-latest java: 11 - epVersion: 2.10.0 + epVersion: 2.11.0 - os: ubuntu-latest java: 11 - epVersion: 2.10.0 + epVersion: 2.11.0 - os: windows-latest java: 11 - epVersion: 2.10.0 + epVersion: 2.11.0 - os: ubuntu-latest java: 17 - epVersion: 2.10.0 + epVersion: 2.11.0 fail-fast: false runs-on: ${{ matrix.os }} steps: diff --git a/RELEASING.md b/RELEASING.md index a848eaf233..3bcbbd1e98 100755 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,3 +1,8 @@ +IMPORTANT: Make sure you are using a JDK 8 JVM by checking `java -version` before any +of the steps below. If you run the steps below on a JDK 11+ JVM, that will break Java +8 support, as the released jars will only run on JDK 11. We do not target Java 8 when +building on JDK 11 since Error Prone has required Java 11 since version 2.11.0. + (Recommended, but optional) Update JarInfer Android SDK Models ============================================================== diff --git a/build.gradle b/build.gradle index 10df553722..5558e11c8e 100644 --- a/build.gradle +++ b/build.gradle @@ -75,9 +75,24 @@ subprojects { project -> } } - if (JavaVersion.current().java9Compatible) { + // We target Java 11 when building on JDK 11+, but Java 8 when building on JDK 8, since + // EP 2.11.0+ requires Java 11 + if (JavaVersion.current() >= JavaVersion.VERSION_11) { tasks.withType(JavaCompile) { - options.release = 8 + java.sourceCompatibility = "11" + java.targetCompatibility = "11" + } + } else { + tasks.withType(JavaCompile) { + java.sourceCompatibility = "1.8" + java.targetCompatibility = "1.8" + } + } + + // Ensure we are running on Java 8 whenever publishing to remote repos + tasks.withType(PublishToMavenRepository) { + doFirst { + assert JavaVersion.current() == JavaVersion.VERSION_1_8 : "Only publish to remote repos on JDK 1.8" } } diff --git a/code-coverage-report/build.gradle b/code-coverage-report/build.gradle index 0862c69d6e..c7cb38eb71 100644 --- a/code-coverage-report/build.gradle +++ b/code-coverage-report/build.gradle @@ -21,6 +21,13 @@ plugins { id 'com.github.kt3k.coveralls' } +// Use JDK 17 for this module, via a toolchain. We need JDK 17 since this module +// depends on jdk17-unit-tests. +// We must null out sourceCompatibility and targetCompatibility to use toolchains. +java.sourceCompatibility = null +java.targetCompatibility = null +java.toolchain.languageVersion.set JavaLanguageVersion.of(17) + // A resolvable configuration to collect source code def sourcesPath = configurations.create("sourcesPath") { visible = false diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index adaa99bb1a..ecd9e24418 100755 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -33,8 +33,9 @@ if (project.hasProperty("epApiVersion")) { def versions = [ asm : "7.1", checkerFramework : "3.21.1", - // The version of Error Prone used to check NullAway's code - errorProne : "2.10.0", + // The version of Error Prone used to check NullAway's code. + // EP 2.10.0 was the last version compatible with Java 8 + errorProne : JavaVersion.current() >= JavaVersion.VERSION_11 ? "2.11.0" : "2.10.0", // The version of Error Prone that NullAway is compiled and tested against errorProneApi : project.hasProperty("epApiVersion") ? epApiVersion : oldestErrorProneApi, support : "27.1.1", diff --git a/jar-infer/jar-infer-cli/build.gradle b/jar-infer/jar-infer-cli/build.gradle index fb0252a2c9..673209a084 100644 --- a/jar-infer/jar-infer-cli/build.gradle +++ b/jar-infer/jar-infer-cli/build.gradle @@ -4,9 +4,6 @@ plugins { id "com.github.johnrengelman.shadow" } -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - repositories { mavenCentral() } diff --git a/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java b/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java index 3a68785a29..dda6aaf47b 100644 --- a/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java +++ b/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java @@ -57,14 +57,15 @@ public class JarInferTest { private CompilationTestHelper compilationTestHelper; - @BugPattern( - name = "DummyChecker", - summary = "Dummy checker to use CompilationTestHelper", - severity = WARNING) /** * A dummy checker to allow us to use {@link CompilationTestHelper} to compile Java code for * testing, as it requires a {@link BugChecker} to run. */ + @BugPattern( + name = "DummyChecker", + summary = "Dummy checker to use CompilationTestHelper", + severity = WARNING) + @SuppressWarnings("BugPatternNaming") // remove once we require EP 2.11+ public static class DummyChecker extends BugChecker { public DummyChecker() {} } diff --git a/jar-infer/nullaway-integration-test/build.gradle b/jar-infer/nullaway-integration-test/build.gradle index f47fe588e5..100e2d81ae 100644 --- a/jar-infer/nullaway-integration-test/build.gradle +++ b/jar-infer/nullaway-integration-test/build.gradle @@ -18,9 +18,6 @@ plugins { id "nullaway.jacoco-conventions" } -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - dependencies { testImplementation deps.test.junit4 testImplementation(deps.build.errorProneTestHelpers) { diff --git a/jar-infer/test-java-lib-jarinfer/build.gradle b/jar-infer/test-java-lib-jarinfer/build.gradle index c38c688808..a6106f305e 100644 --- a/jar-infer/test-java-lib-jarinfer/build.gradle +++ b/jar-infer/test-java-lib-jarinfer/build.gradle @@ -20,9 +20,6 @@ plugins { evaluationDependsOn(":jar-infer:jar-infer-cli") -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - def astubxPath = "com/uber/nullaway/jarinfer/provider/jarinfer.astubx" jar { diff --git a/jdk17-unit-tests/build.gradle b/jdk17-unit-tests/build.gradle index 6752d8a89e..368fd2722b 100644 --- a/jdk17-unit-tests/build.gradle +++ b/jdk17-unit-tests/build.gradle @@ -19,6 +19,9 @@ plugins { } // Use JDK 17 for this module, via a toolchain +// We must null out sourceCompatibility and targetCompatibility to use toolchains. +java.sourceCompatibility = null +java.targetCompatibility = null java.toolchain.languageVersion.set JavaLanguageVersion.of(17) configurations { diff --git a/nullaway/build.gradle b/nullaway/build.gradle index c57c7e2f20..e186037ea4 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -20,9 +20,6 @@ plugins { id 'nullaway.jacoco-conventions' } -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - configurations { nullawayJar } @@ -92,9 +89,26 @@ test { apply plugin: 'com.vanniktech.maven.publish' -// Create a task to build NullAway with NullAway checking enabled -// For some reason, this doesn't work on Java 8 if (JavaVersion.current() >= JavaVersion.VERSION_11) { + // Required on Java 11+ since Error Prone and NullAway access a bunch of + // JDK-internal APIs that are not exposed otherwise + tasks.withType(JavaCompile).configureEach { + options.compilerArgs += [ + "--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.code=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.comp=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-exports=jdk.compiler/com.sun.source.tree=ALL-UNNAMED", + ] + } + // Create a task to build NullAway with NullAway checking enabled + // For some reason, this doesn't work on Java 8 tasks.register('buildWithNullAway', JavaCompile) { // Configure compilation to run with Error Prone and NullAway source = sourceSets.main.java diff --git a/nullaway/src/main/java/com/uber/nullaway/NullAway.java b/nullaway/src/main/java/com/uber/nullaway/NullAway.java index 000571bb9e..6114e59c98 100644 --- a/nullaway/src/main/java/com/uber/nullaway/NullAway.java +++ b/nullaway/src/main/java/com/uber/nullaway/NullAway.java @@ -148,6 +148,7 @@ summary = "Nullability type error.", tags = BugPattern.StandardTags.LIKELY_ERROR, severity = WARNING) +@SuppressWarnings("BugPatternNaming") // remove once we require EP 2.11+ public class NullAway extends BugChecker implements BugChecker.MethodInvocationTreeMatcher, BugChecker.AssignmentTreeMatcher, diff --git a/sample-library-model/build.gradle b/sample-library-model/build.gradle index bd9b7948a5..01ca784f99 100644 --- a/sample-library-model/build.gradle +++ b/sample-library-model/build.gradle @@ -20,9 +20,6 @@ plugins { id "java-library" } -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - dependencies { compileOnly deps.apt.autoService annotationProcessor deps.apt.autoService diff --git a/test-library-models/build.gradle b/test-library-models/build.gradle index bd9b7948a5..01ca784f99 100644 --- a/test-library-models/build.gradle +++ b/test-library-models/build.gradle @@ -20,9 +20,6 @@ plugins { id "java-library" } -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - dependencies { compileOnly deps.apt.autoService annotationProcessor deps.apt.autoService