Skip to content

Commit

Permalink
Rework the way "JDK tests" are done
Browse files Browse the repository at this point in the history
The integration test task is no longer run using a toolchain,
but toolchain is used to determine the installation path and
pass it as system property, that's then used in the TestKit
test project's gradle.properties as org.gradle.java.home.
  • Loading branch information
tbroyer committed Dec 10, 2023
1 parent dc41dd9 commit 5cfcc08
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
8 changes: 0 additions & 8 deletions build-logic/src/main/kotlin/local/java-base.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ plugins {
id("local.base")
`java-base`
}
project.findProperty("test.java-toolchain")?.also { testJavaToolchain ->
tasks.withType<Test>().configureEach {
javaLauncher =
project.javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJavaToolchain.toString())
}
}
}

spotless {
java {
Expand Down
8 changes: 8 additions & 0 deletions build-logic/src/main/kotlin/local/java-library.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ plugins {
tasks.withType<JavaCompile>().configureEach {
options.release = 8
}
project.findProperty("test.java-toolchain")?.also { testJavaToolchain ->
tasks.withType<Test>().configureEach {
javaLauncher =
project.javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJavaToolchain.toString())
}
}
}

dependencies {
errorprone(project.the<VersionCatalogsExtension>().named("libs").findBundle("errorprone").orElseThrow())
Expand Down
22 changes: 9 additions & 13 deletions integTest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ plugins {
`embedded-kotlin`
}

// Use the lowest toolchain to compile the code, such that produced bytecode
// is compatible with the target test toolchain.
project.findProperty("test.java-toolchain")?.also { testJavaToolchain ->
val testVersion = JavaLanguageVersion.of(testJavaToolchain.toString())
if (testVersion < JavaLanguageVersion.of(JavaVersion.current().toString())) {
java {
toolchain {
languageVersion = testVersion
}
}
}
}

// XXX: separate "dependency bucket" from resolvable configuration?
val localMavenRepositories by configurations.creating {
isCanBeDeclared = true
Expand Down Expand Up @@ -47,6 +34,15 @@ tasks {
.withPropertyName("testRepositories")
.withPathSensitivity(PathSensitivity.RELATIVE)

val testJavaToolchain = project.findProperty("test.java-toolchain")
testJavaToolchain?.also {
val metadata =
project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaToolchain.toString()))
}.get().metadata
systemProperty("test.java-home", metadata.installationPath.asFile.canonicalPath)
}

systemProperty("version", rootProject.version.toString())
// systemProperty doesn't support providers, so fake it with CommandLineArgumentProvider
jvmArgumentProviders.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import java.util.Properties

class DynamicIncrementalProcessorIntegrationTest {
@JvmField
@Rule
val testProjectDir = TemporaryFolder()

private val testJavaHome = System.getProperty("test.java-home", System.getProperty("java.home"))

private val version = System.getProperty("version")!!
private val testRepositories =
System.getProperty("testRepositories")!!.splitToSequence(File.pathSeparator).joinToString("\n") {
Expand Down Expand Up @@ -85,6 +88,12 @@ class DynamicIncrementalProcessorIntegrationTest {
}

private fun setupProject() {
testProjectDir.newFile("gradle.properties").outputStream().use {
Properties().apply {
setProperty("org.gradle.java.home", testJavaHome)
store(it, null)
}
}
testProjectDir.newFile("settings.gradle.kts").writeText(
"""
dependencyResolutionManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import java.util.Properties

class IncrementalAnnotationProcessorProcessorIntegrationTest {
@JvmField
@Rule
val testProjectDir = TemporaryFolder()

private val testJavaHome = System.getProperty("test.java-home", System.getProperty("java.home"))

private val version = System.getProperty("version")!!
private val testRepositories =
System.getProperty("testRepositories")!!.splitToSequence(File.pathSeparator).joinToString("\n") {
Expand All @@ -39,6 +42,12 @@ class IncrementalAnnotationProcessorProcessorIntegrationTest {

@Test fun testIncrementality() {
// given
testProjectDir.newFile("gradle.properties").outputStream().use {
Properties().apply {
setProperty("org.gradle.java.home", testJavaHome)
store(it, null)
}
}
testProjectDir.newFile("settings.gradle.kts").writeText(
"""
dependencyResolutionManagement {
Expand Down

0 comments on commit 5cfcc08

Please sign in to comment.