diff --git a/annotations/build.gradle b/annotations/build.gradle index 5ffa3cec63..8c88c7bed2 100644 --- a/annotations/build.gradle +++ b/annotations/build.gradle @@ -20,8 +20,6 @@ plugins { id 'nullaway.jacoco-conventions' } -sourceCompatibility = 1.8 - dependencies { } diff --git a/build.gradle b/build.gradle index 2843a0bbf4..07198f9b0c 100644 --- a/build.gradle +++ b/build.gradle @@ -96,18 +96,11 @@ subprojects { project -> } } - // 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) { - java.sourceCompatibility = "11" - java.targetCompatibility = "11" - } - } else { - tasks.withType(JavaCompile) { - java.sourceCompatibility = "1.8" - java.targetCompatibility = "1.8" - } + // Target JDK 8. We need to use the older sourceCompatibility / targetCompatibility settings to get + // the build to work on JDK 11+. Once we stop supporting JDK 8, switch to using the javac "release" option + tasks.withType(JavaCompile) { + java.sourceCompatibility = "1.8" + java.targetCompatibility = "1.8" } // Ensure we are running on Java 8 whenever publishing to remote repos diff --git a/guava-recent-unit-tests/build.gradle b/guava-recent-unit-tests/build.gradle index f831222651..24dbdfe76b 100644 --- a/guava-recent-unit-tests/build.gradle +++ b/guava-recent-unit-tests/build.gradle @@ -53,3 +53,30 @@ test { ] } } + +if (JavaVersion.current() >= JavaVersion.VERSION_11) { + // Create a task to test on JDK 8 + def jdk8Test = tasks.register("testJdk8", Test) { + onlyIf { + // Only if we are using a version of Error Prone compatible with JDK 8 + deps.versions.errorProneApi == "2.4.0" + } + + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(8) + } + + description = "Runs the test suite on JDK 8" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}" + } + + tasks.named('check').configure { + dependsOn(jdk8Test) + } +} diff --git a/jar-infer/android-jarinfer-models-sdk28/build.gradle b/jar-infer/android-jarinfer-models-sdk28/build.gradle index 9ff005f6ed..fe50fe8f62 100644 --- a/jar-infer/android-jarinfer-models-sdk28/build.gradle +++ b/jar-infer/android-jarinfer-models-sdk28/build.gradle @@ -2,8 +2,6 @@ plugins { id "java-library" } -sourceCompatibility = 1.8 - repositories { mavenCentral() } diff --git a/jar-infer/android-jarinfer-models-sdk29/build.gradle b/jar-infer/android-jarinfer-models-sdk29/build.gradle index 9ff005f6ed..fe50fe8f62 100644 --- a/jar-infer/android-jarinfer-models-sdk29/build.gradle +++ b/jar-infer/android-jarinfer-models-sdk29/build.gradle @@ -2,8 +2,6 @@ plugins { id "java-library" } -sourceCompatibility = 1.8 - repositories { mavenCentral() } diff --git a/jar-infer/android-jarinfer-models-sdk30/build.gradle b/jar-infer/android-jarinfer-models-sdk30/build.gradle index 9ff005f6ed..fe50fe8f62 100644 --- a/jar-infer/android-jarinfer-models-sdk30/build.gradle +++ b/jar-infer/android-jarinfer-models-sdk30/build.gradle @@ -2,8 +2,6 @@ plugins { id "java-library" } -sourceCompatibility = 1.8 - repositories { mavenCentral() } diff --git a/jar-infer/android-jarinfer-models-sdk31/build.gradle b/jar-infer/android-jarinfer-models-sdk31/build.gradle index 9ff005f6ed..fe50fe8f62 100644 --- a/jar-infer/android-jarinfer-models-sdk31/build.gradle +++ b/jar-infer/android-jarinfer-models-sdk31/build.gradle @@ -2,8 +2,6 @@ plugins { id "java-library" } -sourceCompatibility = 1.8 - repositories { mavenCentral() } diff --git a/jar-infer/jar-infer-cli/build.gradle b/jar-infer/jar-infer-cli/build.gradle index 8744bc3524..e0a5090876 100644 --- a/jar-infer/jar-infer-cli/build.gradle +++ b/jar-infer/jar-infer-cli/build.gradle @@ -125,6 +125,7 @@ publishing { project.tasks.named('publishShadowPublicationToMavenLocal').configure { dependsOn 'sourcesJar' dependsOn 'simpleJavadocJar' + dependsOn 'signMavenPublication' } } } diff --git a/jar-infer/jar-infer-lib/build.gradle b/jar-infer/jar-infer-lib/build.gradle index 638ae2de31..1bcf4ae9ff 100644 --- a/jar-infer/jar-infer-lib/build.gradle +++ b/jar-infer/jar-infer-lib/build.gradle @@ -18,8 +18,6 @@ plugins { id 'nullaway.jacoco-conventions' } -sourceCompatibility = 1.8 - repositories { mavenCentral() // uncomment if you want to use wala.dalvik or wala.scandroid diff --git a/jar-infer/test-android-lib-jarinfer/build.gradle b/jar-infer/test-android-lib-jarinfer/build.gradle index db29e5756a..b79ed03539 100644 --- a/jar-infer/test-android-lib-jarinfer/build.gradle +++ b/jar-infer/test-android-lib-jarinfer/build.gradle @@ -16,8 +16,6 @@ apply plugin: 'com.android.library' -sourceCompatibility = 1.8 - android { compileSdkVersion deps.build.compileSdkVersion diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 3b4f10f379..a4df4148e7 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -101,25 +101,53 @@ test { apply plugin: 'com.vanniktech.maven.publish' 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", - ] +// These --add-exports arguments are required when targeting JDK 11+ since Error Prone and NullAway access a bunch of +// JDK-internal APIs that are not exposed otherwise. Since we currently target JDK 8, we do not need to pass the +// arguments, as encapsulation of JDK internals is not enforced on JDK 8. In fact, the arguments cause a compiler error +// when targeting JDK 8. Leaving commented so we can easily add them back once we target JDK 11. +// 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 test on JDK 8 + def jdk8Test = tasks.register("testJdk8", Test) { + onlyIf { + // Only if we are using a version of Error Prone compatible with JDK 8 + deps.versions.errorProneApi == "2.4.0" + } + + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(8) + } + + description = "Runs the test suite on JDK 8" + group = LifecycleBasePlugin.VERIFICATION_GROUP + + // Copy inputs from normal Test task. + def testTask = tasks.getByName("test") + classpath = testTask.classpath + testClassesDirs = testTask.testClassesDirs + jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}" } + + tasks.named('check').configure { + dependsOn(jdk8Test) + } + // Create a task to build NullAway with NullAway checking enabled - // For some reason, this doesn't work on Java 8 + // (For some reason, this doesn't work on Java 8) tasks.register('buildWithNullAway', JavaCompile) { onlyIf { // We only do NullAway checks when compiling against the latest diff --git a/sample/build.gradle b/sample/build.gradle index 2586c8dee7..7c80543b4d 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -20,9 +20,6 @@ plugins { id "java-library" } -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - dependencies { annotationProcessor project(":nullaway") annotationProcessor project(path: ":sample-library-model") diff --git a/test-java-lib-lombok/build.gradle b/test-java-lib-lombok/build.gradle index 8e8d7c5a94..2065f7cdcc 100644 --- a/test-java-lib-lombok/build.gradle +++ b/test-java-lib-lombok/build.gradle @@ -20,9 +20,6 @@ plugins { id "java-library" } -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - dependencies { annotationProcessor project(":nullaway") annotationProcessor deps.test.lombok diff --git a/test-java-lib/build.gradle b/test-java-lib/build.gradle index 9fda6c3bef..f877afb08e 100644 --- a/test-java-lib/build.gradle +++ b/test-java-lib/build.gradle @@ -20,9 +20,6 @@ plugins { id "java-library" } -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - dependencies { annotationProcessor project(":nullaway") implementation deps.build.jspecify