Skip to content

Commit

Permalink
Provide test jdk via toolchain api (#2664)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyTsvetkov authored Jan 26, 2023
1 parent d8af3d6 commit b055763
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions gradle-plugins/buildSrc/src/main/kotlin/gradleUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.testing.Test
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
Expand All @@ -24,22 +26,13 @@ inline fun <reified T> Project.configureIfExists(fn: T.() -> Unit) {
extensions.findByType(T::class.java)?.fn()
}

val javaHomeForTests: String? = when {
// __COMPOSE_NATIVE_DISTRIBUTIONS_MIN_JAVA_VERSION__
JavaVersion.current() >= JavaVersion.VERSION_15 -> System.getProperty("java.home")
else -> System.getenv("JDK_15")
?: System.getenv("JDK_FOR_GRADLE_TESTS")
}

val isWindows = DefaultNativePlatform.getCurrentOperatingSystem().isWindows

fun Test.configureJavaForComposeTest() {
if (javaHomeForTests != null) {
val executableFileName = if (isWindows) "java.exe" else "java"
executable = File(javaHomeForTests).resolve("bin/$executableFileName").absolutePath
} else {
doFirst { error("Use JDK 15+ to run tests or set up JDK_15/JDK_FOR_GRADLE_TESTS env. var") }
}
val toolchains = project.extensions.getByName("javaToolchains") as JavaToolchainService
javaLauncher.set(toolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(16))
})
}

fun Project.configureAllTests(fn: Test.() -> Unit = {}) {
Expand Down

0 comments on commit b055763

Please sign in to comment.