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

Recompile Java-test/src/test before running it for each supported jdk #4129

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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
50 changes: 37 additions & 13 deletions retrofit/java-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,50 @@ tasks.withType(JavaCompile).configureEach {
options.compilerArgs << '-parameters'
}

// Create a test task for each supported JDK.
(8..21).each { majorVersion ->
def jdkTest = tasks.register("testJdk$majorVersion", Test) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(majorVersion)
ext {
testSrcDirs = sourceSets.named('test').get().java.getSourceDirectories().asPath
}

def addTestTaskFor(int jdkVersion) {
def testTaskName = "testJdk$jdkVersion"
// Set up a new source set for the test task
def testSourceSet = sourceSets.create(testTaskName)
// Its srcDir is the same as the built-in test task
testSourceSet.java.srcDir(testSrcDirs)
// It requires all the same dependencies that the built-in tests have
// Thus, use 'extendsFrom testImplementation' to make all the declared dependencies of
// the built-in tests also become dependencies of this task
configurations.getByName("${testTaskName}Implementation").extendsFrom(configurations.getByName('testImplementation'))
// it use javaCompiler for the specified jdkVersion to compile srdDir
tasks.named("compileTestJdk${jdkVersion}Java", JavaCompile) {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(jdkVersion)
vendor = JvmVendorSpec.AZUL
}

description = "Runs the test suite on JDK $majorVersion"
}
// Create test task
tasks.register(testTaskName, Test) {
description = "Runs the test suite on JDK $jdkVersion"
group = LifecycleBasePlugin.VERIFICATION_GROUP

// Copy inputs from normal Test task.
def testTask = tasks.getByName("test")
classpath = testTask.classpath
testClassesDirs = testTask.testClassesDirs
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(jdkVersion)
vendor = JvmVendorSpec.AZUL
}

testClassesDirs = sourceSets.named(testTaskName).get().output.classesDirs
classpath = sourceSets.named(testTaskName).get().runtimeClasspath
}
tasks.named("check").configure {
dependsOn(jdkTest)

tasks.named('check') {
dependsOn(testTaskName)
}
}

// Create a test task for each supported JDK.
(8..21).each { majorVersion ->
addTestTaskFor(majorVersion)
}

// We don't need the built-in task which uses Gradle's JVM given the above variants.
tasks.getByName('test').enabled = false