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

Run tests on JDK 21 #826

Merged
merged 14 commits into from
Sep 5, 2023
5 changes: 5 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 1 addition & 20 deletions annotations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,10 @@ 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",
]
}

apply plugin: 'com.vanniktech.maven.publish'
62 changes: 0 additions & 62 deletions buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle

This file was deleted.

120 changes: 120 additions & 0 deletions buildSrc/src/main/groovy/nullaway.java-test-conventions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright (C) 2021. Uber Technologies
msridhar marked this conversation as resolved.
Show resolved Hide resolved
*
* 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
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)
}

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 testJdk21
}
3 changes: 1 addition & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
21 changes: 1 addition & 20 deletions guava-recent-unit-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
24 changes: 7 additions & 17 deletions jar-infer/jar-infer-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,25 +48,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",
// Accessed by Lombok tests
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
]
dependsOn ':jar-infer:test-android-lib-jarinfer:bundleReleaseAar'
}

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"
}
Expand Down
20 changes: 1 addition & 19 deletions jar-infer/nullaway-integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
plugins {
id "java-library"
id "nullaway.jacoco-conventions"
id "nullaway.java-test-conventions"
}

dependencies {
Expand All @@ -26,21 +26,3 @@ dependencies {
testImplementation project(":nullaway")
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",
]
}
22 changes: 9 additions & 13 deletions jdk17-unit-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,19 +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}"
]
}

tasks.getByName('testJdk21').configure {
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
Loading