Browse Source

Add gradle "8.6" and AGP "7.3.1", "8.2.2" to the gradle plugin integration tests (#4309)

pull/4474/head
Konstantin 10 months ago committed by Igor Demin
parent
commit
e9c11b0a92
  1. 3
      .github/workflows/gradle-plugin.yml
  2. 1
      gradle-plugins/buildSrc/src/main/kotlin/gradleUtils.kt
  3. 46
      gradle-plugins/compose/build.gradle.kts
  4. 36
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
  5. 8
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt
  6. 18
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/GradleTestNameGenerator.kt
  7. 15
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestKotlinVersions.kt
  8. 15
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt
  9. 12
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProperties.kt
  10. 1
      gradle-plugins/compose/src/test/test-projects/application/mpp/build.gradle
  11. 7
      gradle-plugins/gradle.properties

3
.github/workflows/gradle-plugin.yml

@ -18,6 +18,7 @@ jobs:
matrix:
os: [ubuntu-20.04, macos-12, windows-2022]
gradle: [7.4, 8.3]
agp: [7.3.1, 8.2.2]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
@ -30,7 +31,7 @@ jobs:
run: |
cd gradle-plugins
./gradlew assemble
./gradlew --continue :preview-rpc:test :compose:test :compose:testGradle-${{ matrix.gradle }}
./gradlew --continue :preview-rpc:test :compose:test ':compose:test-Gradle(${{ matrix.gradle }})-Agp(${{ matrix.agp }})'
- name: Upload Reports
uses: actions/upload-artifact@v2
with:

1
gradle-plugins/buildSrc/src/main/kotlin/gradleUtils.kt

@ -64,6 +64,7 @@ inline fun <reified T : Task> TaskContainer.registerVerificationTask(
crossinline fn: T.() -> Unit
): TaskProvider<T> =
register(name, T::class) {
group = "verification"
fn()
}.apply {
named("check").dependsOn(this)

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

@ -93,10 +93,13 @@ val jar = tasks.named<Jar>("jar") {
this.duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
val supportedGradleVersions = project.property("compose.tests.gradle.versions")
.toString().split(",")
.map { it.trim() }
.map { GradleVersion.version(it) }
val supportedGradleVersions = project.propertyList("compose.tests.gradle.versions")
val supportedAgpVersions = project.propertyList("compose.tests.agp.versions")
fun Project.propertyList(name: String) =
project.property(name).toString()
.split(",")
.map { it.trim() }
val gradleTestsPattern = "org.jetbrains.compose.test.tests.integration.*"
@ -151,17 +154,30 @@ for (jdkVersion in jdkVersionsForTests) {
}
for (gradleVersion in supportedGradleVersions) {
tasks.registerVerificationTask<Test>("testGradle-${gradleVersion.version}") {
classpath = tasks.test.get().classpath
dependsOn(downloadJdksForTests)
systemProperty("compose.tests.gradle.test.jdks.root", jdkForTestsRoot.absolutePath)
if (gradleVersion >= GradleVersion.version("7.6")) {
systemProperty("compose.tests.gradle.configuration.cache", "true")
}
systemProperty("compose.tests.gradle.version", gradleVersion.version)
filter {
includeTestsMatching(gradleTestsPattern)
for (agpVersion in supportedAgpVersions) {
tasks.registerVerificationTask<Test>("test-Gradle(${gradleVersion})-Agp($agpVersion)") {
classpath = tasks.test.get().classpath
filter { includeTestsMatching(gradleTestsPattern) }
dependsOn(downloadJdksForTests)
/*
* Fixes this kind of error:
* What went wrong:
* An exception occurred applying plugin request [id: 'com.android.application', version: '8.2.2']
* > Failed to apply plugin 'com.android.internal.version-check'.
* > Minimum supported Gradle version is 8.2. Current version is 7.4.
*/
val agpMajor = agpVersion.split('.').first().toInt()
val gradleMajor = gradleVersion.split('.').first().toInt()
onlyIf { agpMajor <= gradleMajor }
systemProperty("compose.tests.gradle.test.jdks.root", jdkForTestsRoot.absolutePath)
systemProperty("compose.tests.gradle.version", gradleVersion)
systemProperty("compose.tests.agp.version", agpVersion)
systemProperty(
"compose.tests.gradle.configuration.cache",
GradleVersion.version(gradleVersion) >= GradleVersion.version("8.0")
)
}
}
}

36
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

@ -24,6 +24,8 @@ import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import kotlin.concurrent.thread
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import java.io.File
class GradlePluginTest : GradlePluginTestBase() {
@ -64,22 +66,15 @@ class GradlePluginTest : GradlePluginTestBase() {
)
}
// We rely on this property to use gradle configuration cache in some tests.
// Enabling configuration cache unconditionally breaks out tests with gradle 7.3.3.
// Old comment: 'for some reason configuration cache + test kit + custom vars does not work'
private val GradleVersion.isAtLeastGradle8
get() = this >= GradleVersion.version("8.0")
@Test
fun iosResources() {
Assumptions.assumeTrue(currentOS == OS.MacOS)
val iosTestEnv = iosTestEnv()
val testEnv = defaultTestEnvironment.copy(
useGradleConfigurationCache = TestProperties.gradleBaseVersionForTests.isAtLeastGradle8,
additionalEnvVars = iosTestEnv.envVars
)
with(testProject(TestProjects.iosResources, testEnv)) {
with(TestProject(TestProjects.iosResources, testEnv)) {
gradle(":embedAndSignAppleFrameworkForXcode", "--dry-run").checks {
// This test is not intended to actually run embedAndSignAppleFrameworkForXcode.
// Instead, it should check that embedAndSign depends on syncComposeResources using dry run
@ -96,11 +91,7 @@ class GradlePluginTest : GradlePluginTestBase() {
@Test
fun iosTestResources() {
Assumptions.assumeTrue(currentOS == OS.MacOS)
val testEnv = defaultTestEnvironment.copy(
useGradleConfigurationCache = TestProperties.gradleBaseVersionForTests.isAtLeastGradle8
)
with(testProject(TestProjects.iosResources, testEnv)) {
with(testProject(TestProjects.iosResources)) {
gradle(":linkDebugTestIosX64", "--dry-run").checks {
check.taskSkipped(":copyTestComposeResourcesForIosX64")
check.taskSkipped(":linkDebugTestIosX64")
@ -117,7 +108,6 @@ class GradlePluginTest : GradlePluginTestBase() {
Assumptions.assumeTrue(currentOS == OS.MacOS)
val iosTestEnv = iosTestEnv()
val testEnv = defaultTestEnvironment.copy(
useGradleConfigurationCache = TestProperties.gradleBaseVersionForTests.isAtLeastGradle8,
additionalEnvVars = iosTestEnv.envVars
)
with(testProject(TestProjects.iosMokoResources, testEnv)) {
@ -138,11 +128,6 @@ class GradlePluginTest : GradlePluginTestBase() {
@Test
fun nativeCacheKind() {
Assumptions.assumeTrue(currentOS == OS.MacOS)
fun nativeCacheKindProject(kotlinVersion: String) = testProject(
TestProjects.nativeCacheKind,
defaultTestEnvironment.copy(kotlinVersion = kotlinVersion, useGradleConfigurationCache = false)
)
val task = if (currentArch == Arch.X64) {
":subproject:linkDebugFrameworkIosX64"
} else {
@ -153,11 +138,14 @@ class GradlePluginTest : GradlePluginTestBase() {
// the compiler crashed (older k/native doesn't support libs built using newer k/native):
// e: kotlin.NotImplementedError: Generation of stubs for class org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterPublicSymbolImpl is not supported yet
val defaultKotlinVersion = kotlinVersionNumbers(TestKotlinVersions.Default)
if (defaultKotlinVersion >= KotlinVersion(1, 9, 20)) {
if (kotlinVersionNumbers(defaultTestEnvironment.kotlinVersion) >= KotlinVersion(1, 9, 20)) {
testWorkDir.deleteRecursively()
testWorkDir.mkdirs()
with(nativeCacheKindProject(TestKotlinVersions.Default) ) {
val project = TestProject(
TestProjects.nativeCacheKind,
defaultTestEnvironment.copy(useGradleConfigurationCache = false)
)
with(project) {
gradle(task, "--info").checks {
check.taskSuccessful(task)
check.logContains("-Xauto-cache-from=")
@ -220,7 +208,7 @@ class GradlePluginTest : GradlePluginTestBase() {
}
}
testKotlinVersion(TestKotlinVersions.v1_9_21)
testKotlinVersion("1.9.21")
}
@Test
@ -251,7 +239,7 @@ class GradlePluginTest : GradlePluginTestBase() {
@Test
fun newAndroidTarget() {
Assumptions.assumeTrue(TestProperties.gradleBaseVersionForTests >= GradleVersion.version("8.0.0"))
Assumptions.assumeTrue(defaultTestEnvironment.parsedGradleVersion >= GradleVersion.version("8.0.0"))
with(testProject(TestProjects.newAndroidTarget)) {
gradle("build", "--dry-run").checks {
}

8
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt

@ -212,14 +212,14 @@ class ResourcesTest : GradlePluginTestBase() {
commonResourcesFiles.forEach { res ->
if (res == "font/emptyFont.otf") {
//android fonts should be only in assets
assertNull(zip.getEntry(res))
assertNull(zip.getEntry(res), "file = '$res'")
} else {
assertNotNull(zip.getEntry(res))
assertNotNull(zip.getEntry(res), "file = '$res'")
}
}
assertNotNull(zip.getEntry("assets/font/emptyFont.otf"))
assertNotNull(zip.getEntry("assets/font/emptyFont.otf"), "file = 'assets/font/emptyFont.otf'")
val platformTxt = zip.getEntry("files/platform.txt")
assertNotNull(platformTxt)
assertNotNull(platformTxt, "file = 'files/platform.txt'")
val text = zip.getInputStream(platformTxt).readBytes().decodeToString()
assertEquals("android $flavor-$type", text)
}

18
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/GradleTestNameGenerator.kt

@ -6,10 +6,22 @@
package org.jetbrains.compose.test.utils
import org.junit.jupiter.api.DisplayNameGenerator
import java.lang.reflect.Method
class GradleTestNameGenerator : DisplayNameGenerator.Standard() {
private val gradleVersion = TestProperties.gradleVersionForTests?.let { "[Gradle '$it']" } ?: ""
override fun generateDisplayNameForClass(testClass: Class<*>?): String =
super.generateDisplayNameForClass(testClass) + gradleVersion
override fun generateDisplayNameForMethod(testClass: Class<*>, testMethod: Method) =
testMethod.name + with(TestProperties) {
mutableListOf<String>().apply {
muteException { add("kotlin=$composeCompilerCompatibleKotlinVersion") }
muteException { add("gradle=$gradleVersion") }
muteException { add("agp=$agpVersion") }
}.joinToString(prefix = "(", separator = ", ", postfix = ")")
}
private fun muteException(fn: () -> Unit) = try {
fn()
} catch (_: Exception) {
//do nothing
}
}

15
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestKotlinVersions.kt

@ -1,15 +0,0 @@
/*
* Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package org.jetbrains.compose.test.utils
object TestKotlinVersions {
val Default = TestProperties.composeCompilerCompatibleKotlinVersion
val v1_8_20 = "1.8.20"
val v1_9_0 = "1.9.0"
val v1_9_10 = "1.9.10"
val v1_9_20_Beta = "1.9.20-Beta"
val v1_9_21 = "1.9.21"
}

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

@ -9,13 +9,16 @@ import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.util.GradleVersion
import org.jetbrains.compose.desktop.application.internal.ComposeProperties
import org.junit.jupiter.params.provider.Arguments
import java.io.File
import java.util.Properties
import java.util.stream.Stream
data class TestEnvironment(
val workingDir: File,
val kotlinVersion: String = TestKotlinVersions.Default,
val agpVersion: String = "7.3.1",
val kotlinVersion: String = TestProperties.composeCompilerCompatibleKotlinVersion,
val gradleVersion: String = TestProperties.gradleVersion,
val agpVersion: String = TestProperties.agpVersion,
val composeGradlePluginVersion: String = TestProperties.composeGradlePluginVersion,
val mokoResourcesPluginVersion: String = "0.23.0",
val composeCompilerPlugin: String? = null,
@ -42,6 +45,8 @@ data class TestEnvironment(
}
file.writeText(content)
}
val parsedGradleVersion: GradleVersion = GradleVersion.version(gradleVersion)
}
private val testJdks = TestProperties
@ -57,7 +62,7 @@ class TestProject(
"--stacktrace",
"--init-script", testProjectsRootDir.resolve("init.gradle").absolutePath,
"-P${ComposeProperties.VERBOSE}=${testEnvironment.composeVerbose}",
if (GradleVersion.version(TestProperties.gradleVersionForTests).baseVersion < GradleVersion.version("8.0")) {
if (testEnvironment.parsedGradleVersion < GradleVersion.version("8.0")) {
null
} else {
"-Porg.gradle.java.installations.paths=${testJdks.joinToString(",")}"
@ -89,7 +94,7 @@ class TestProject(
private inline fun withGradleRunner(args: Array<out String>, runnerFn: GradleRunner.() -> BuildResult): BuildResult {
if (testEnvironment.useGradleConfigurationCache) {
if (TestProperties.gradleBaseVersionForTests < GradleVersion.version("8.0")) {
if (testEnvironment.parsedGradleVersion < GradleVersion.version("8.0")) {
// Gradle 7.* does not use the configuration cache in the same build.
// In other words, if cache misses, Gradle performs configuration,
// but does not, use the serialized task graph.
@ -123,7 +128,7 @@ class TestProject(
}
return GradleRunner.create().apply {
withGradleVersion(TestProperties.gradleVersionForTests)
withGradleVersion(testEnvironment.gradleVersion)
withProjectDir(testEnvironment.workingDir)
withArguments(allArgs)
if (testEnvironment.additionalEnvVars.isNotEmpty()) {

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

@ -5,11 +5,8 @@
package org.jetbrains.compose.test.utils
import org.gradle.util.GradleVersion
import java.io.File
private const val COMPOSE_TESTS_GRADLE_VERSION_PROPERTY = "compose.tests.gradle.version"
object TestProperties {
val composeCompilerVersion: String
get() = notNullSystemProperty("compose.tests.compiler.version")
@ -23,12 +20,11 @@ object TestProperties {
val composeGradlePluginVersion: String
get() = notNullSystemProperty("compose.tests.compose.gradle.plugin.version")
val gradleVersionForTests: String
get() = System.getProperty(COMPOSE_TESTS_GRADLE_VERSION_PROPERTY)
?: error("System property '$COMPOSE_TESTS_GRADLE_VERSION_PROPERTY' is not set")
val gradleVersion: String
get() = notNullSystemProperty("compose.tests.gradle.version")
val gradleBaseVersionForTests: GradleVersion
get() = GradleVersion.version(gradleVersionForTests).baseVersion
val agpVersion: String
get() = notNullSystemProperty("compose.tests.agp.version")
val gradleConfigurationCache: Boolean
get() = System.getProperty("compose.tests.gradle.configuration.cache") == "true"

1
gradle-plugins/compose/src/test/test-projects/application/mpp/build.gradle

@ -29,6 +29,7 @@ kotlin {
}
android {
namespace = "org.jetbrains.compose.testapp"
compileSdk = 31
defaultConfig {

7
gradle-plugins/gradle.properties

@ -13,7 +13,14 @@ compose.tests.compiler.compatible.kotlin.version=1.9.22
compose.tests.js.compiler.compatible.kotlin.version=1.9.22
# __SUPPORTED_GRADLE_VERSIONS__
# Don't forget to edit versions in .github/workflows/gradle-plugin.yml as well
# minimal and current gradle version
#
# !!! we can't update to the gradle upper than 8.3 because of on issue:
# https://github.com/gradle/gradle/issues/26912
# It fails DesktopApplicationTest.proguard test on Windows
# Should be fixed in 8.7
compose.tests.gradle.versions=7.4, 8.3
compose.tests.agp.versions=7.3.1, 8.2.2
# A version of Gradle plugin, that will be published,
# unless overridden by COMPOSE_GRADLE_PLUGIN_VERSION env var.

Loading…
Cancel
Save