Browse Source

Test plugin against multiple versions of Gradle

pull/113/head
Alexey Tsvetkov 4 years ago committed by Alexey Tsvetkov
parent
commit
fbc51e4019
  1. 34
      gradle-plugins/compose/build.gradle.kts
  2. 5
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProject.kt
  3. 2
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProperties.kt

34
gradle-plugins/compose/build.gradle.kts

@ -57,24 +57,34 @@ val jar = tasks.named<Jar>("jar") {
this.duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
val gradleVersionForTests = "6.7"
val minGradleVersionForTests = "6.4"
val maxGradleVersionForTests = "6.7"
val java14Home: String? = when (JavaVersion.current()) {
JavaVersion.VERSION_14 -> System.getProperty("java.home")
else -> System.getenv("JDK_14")
}
val isWindows = getCurrentOperatingSystem().isWindows
afterEvaluate {
tasks.named<Test>("test") {
dependsOn("publishToMavenLocal")
systemProperty("compose.plugin.version", BuildProperties.deployVersion(project))
systemProperty("gradle.version.for.tests", gradleVersionForTests)
tasks.test {
configureTest(maxGradleVersionForTests)
}
if (java14Home != null) {
val executableFileName = if (isWindows) "java.exe" else "java"
executable = File(java14Home).resolve("bin/$executableFileName").absolutePath
} else {
doFirst { error("Use JDK 14 to run tests or set up JDK_14 env. var") }
}
tasks.register("testMinGradleVersion", Test::class.java) {
tasks.test.get().let { defaultTest ->
classpath = defaultTest.classpath
}
configureTest(minGradleVersionForTests)
}
fun Test.configureTest(gradleVersion: String) {
dependsOn("publishToMavenLocal")
systemProperty("compose.plugin.version", BuildProperties.deployVersion(project))
systemProperty("gradle.version.for.tests", gradleVersion)
if (java14Home != null) {
val executableFileName = if (isWindows) "java.exe" else "java"
executable = File(java14Home).resolve("bin/$executableFileName").absolutePath
} else {
doFirst { error("Use JDK 14 to run tests or set up JDK_14 env. var") }
}
}

5
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProject.kt

@ -5,8 +5,7 @@ import java.io.File
data class TestProject(
private val name: String,
private val workingDir: File,
private val defaultGradleVersion: String = TestProperties.defaultGradleVersionForTests
private val workingDir: File
) {
private val additionalArgs = listOf("--stacktrace")
@ -32,7 +31,7 @@ data class TestProject(
fun gradle(vararg args: String): GradleRunner =
GradleRunner.create().apply {
withGradleVersion(defaultGradleVersion)
withGradleVersion(TestProperties.gradleVersionForTests)
withProjectDir(workingDir)
withArguments(args.toList() + additionalArgs)
}

2
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProperties.kt

@ -7,6 +7,6 @@ object TestProperties {
val composeVersion: String
get() = System.getProperty("compose.plugin.version")!!
val defaultGradleVersionForTests: String
val gradleVersionForTests: String
get() = System.getProperty("gradle.version.for.tests")!!
}
Loading…
Cancel
Save