Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test on JDK 22 #992

Merged
merged 8 commits into from
Jul 8, 2024
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
73 changes: 37 additions & 36 deletions buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {
}

jacoco {
toolVersion = "0.8.10"
toolVersion = "0.8.12"
}

// Do not generate reports for individual projects
Expand Down Expand Up @@ -64,46 +64,47 @@ test {
]
}

// Create a task to test on JDK 21
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
}
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(21)
}
// Tasks for testing on other JDK versions; see https://jakewharton.com/build-on-latest-java-test-through-lowest-java/
[21, 22].each { majorVersion ->
def jdkTest = tasks.register("testJdk$majorVersion", Test) {
onlyIf {
// Only run when using the latest Error Prone version
deps.versions.errorProneApi == deps.versions.errorProneLatest
}
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(majorVersion)
}

description = "Runs the test suite on JDK 21"
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs the test suite on JDK $majorVersion"
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",
]
}
// 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 testJdk21
tasks.named('check').configure {
dependsOn jdkTest
}
}


// Share the coverage data to be aggregated for the whole product
configurations.create('coverageDataElements') {
visible = false
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,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:5.5.0",
mockito : "org.mockito:mockito-core:5.12.0",
javaxAnnotationApi : "javax.annotation:javax.annotation-api:1.3.2",
assertJ : "org.assertj:assertj-core:3.23.1",
]
Expand Down
5 changes: 5 additions & 0 deletions jar-infer/jar-infer-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ test {
dependsOn ':jar-infer:test-android-lib-jarinfer:bundleReleaseAar'
}

tasks.getByName('testJdk22').configure {
// Won't work until WALA supports JDK 22; see https://github.com/wala/WALA/issues/1414
onlyIf { false }
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"
}
Expand Down
4 changes: 2 additions & 2 deletions jdk-recent-unit-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ dependencies {
testModulePath deps.test.cfQual
}

test {
jvmArgs += [
tasks.withType(Test).configureEach { test ->
test.jvmArgs += [
// Expose a module path for tests as a JVM property.
// Used by com.uber.nullaway.jdk17.NullAwayModuleInfoTests
"-Dtest.module.path=${configurations.testModulePath.asPath}"
Expand Down
8 changes: 2 additions & 6 deletions jmh/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ jmh {
// includes = ['DFlowMicro']
}

tasks.named('test') {
tasks.withType(Test).configureEach { test ->
// pass the extra JVM args so we can compile benchmarks in unit tests
jvmArgs += extraJVMArgs
}

tasks.getByName('testJdk21').configure {
jvmArgs += extraJVMArgs
test.jvmArgs += extraJVMArgs
}
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ private static class DefaultLibraryModels implements LibraryModels {
"com.google.common.base.Preconditions",
"<T>checkNotNull(T,java.lang.String,java.lang.Object...)"),
0)
// For JDK 22
// TODO check if this is still needed in JDK 23 / subsequent releases
.put(
methodRef(
"com.google.common.base.Preconditions",
"<T>checkNotNull(T,java.lang.String,[email protected] Object...)"),
0)
.put(
methodRef(
"com.google.common.base.Preconditions",
Expand Down Expand Up @@ -516,6 +523,13 @@ private static class DefaultLibraryModels implements LibraryModels {
"com.google.common.base.Verify",
"<T>verifyNotNull(T,java.lang.String,java.lang.Object...)"),
0)
// For JDK 22
// TODO check if this is still needed in JDK 23 / subsequent releases
.put(
methodRef(
"com.google.common.base.Verify",
"<T>verifyNotNull(T,java.lang.String,[email protected] Object...)"),
0)
.put(methodRef("java.util.Objects", "<T>requireNonNull(T)"), 0)
.put(methodRef("java.util.Objects", "<T>requireNonNull(T,java.lang.String)"), 0)
.put(
Expand Down