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. 20
      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

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

@ -57,18 +57,29 @@ val jar = tasks.named<Jar>("jar") {
this.duplicatesStrategy = DuplicatesStrategy.INCLUDE this.duplicatesStrategy = DuplicatesStrategy.INCLUDE
} }
val gradleVersionForTests = "6.7" val minGradleVersionForTests = "6.4"
val maxGradleVersionForTests = "6.7"
val java14Home: String? = when (JavaVersion.current()) { val java14Home: String? = when (JavaVersion.current()) {
JavaVersion.VERSION_14 -> System.getProperty("java.home") JavaVersion.VERSION_14 -> System.getProperty("java.home")
else -> System.getenv("JDK_14") else -> System.getenv("JDK_14")
} }
val isWindows = getCurrentOperatingSystem().isWindows val isWindows = getCurrentOperatingSystem().isWindows
afterEvaluate { tasks.test {
tasks.named<Test>("test") { configureTest(maxGradleVersionForTests)
}
tasks.register("testMinGradleVersion", Test::class.java) {
tasks.test.get().let { defaultTest ->
classpath = defaultTest.classpath
}
configureTest(minGradleVersionForTests)
}
fun Test.configureTest(gradleVersion: String) {
dependsOn("publishToMavenLocal") dependsOn("publishToMavenLocal")
systemProperty("compose.plugin.version", BuildProperties.deployVersion(project)) systemProperty("compose.plugin.version", BuildProperties.deployVersion(project))
systemProperty("gradle.version.for.tests", gradleVersionForTests) systemProperty("gradle.version.for.tests", gradleVersion)
if (java14Home != null) { if (java14Home != null) {
val executableFileName = if (isWindows) "java.exe" else "java" val executableFileName = if (isWindows) "java.exe" else "java"
@ -76,5 +87,4 @@ afterEvaluate {
} else { } else {
doFirst { error("Use JDK 14 to run tests or set up JDK_14 env. var") } 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( data class TestProject(
private val name: String, private val name: String,
private val workingDir: File, private val workingDir: File
private val defaultGradleVersion: String = TestProperties.defaultGradleVersionForTests
) { ) {
private val additionalArgs = listOf("--stacktrace") private val additionalArgs = listOf("--stacktrace")
@ -32,7 +31,7 @@ data class TestProject(
fun gradle(vararg args: String): GradleRunner = fun gradle(vararg args: String): GradleRunner =
GradleRunner.create().apply { GradleRunner.create().apply {
withGradleVersion(defaultGradleVersion) withGradleVersion(TestProperties.gradleVersionForTests)
withProjectDir(workingDir) withProjectDir(workingDir)
withArguments(args.toList() + additionalArgs) 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 val composeVersion: String
get() = System.getProperty("compose.plugin.version")!! get() = System.getProperty("compose.plugin.version")!!
val defaultGradleVersionForTests: String val gradleVersionForTests: String
get() = System.getProperty("gradle.version.for.tests")!! get() = System.getProperty("gradle.version.for.tests")!!
} }
Loading…
Cancel
Save