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 9 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. 38
      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: matrix:
os: [ubuntu-20.04, macos-12, windows-2022] os: [ubuntu-20.04, macos-12, windows-2022]
gradle: [7.4, 8.3] gradle: [7.4, 8.3]
agp: [7.3.1, 8.2.2]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -30,7 +31,7 @@ jobs:
run: | run: |
cd gradle-plugins cd gradle-plugins
./gradlew assemble ./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 - name: Upload Reports
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: 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 crossinline fn: T.() -> Unit
): TaskProvider<T> = ): TaskProvider<T> =
register(name, T::class) { register(name, T::class) {
group = "verification"
fn() fn()
}.apply { }.apply {
named("check").dependsOn(this) named("check").dependsOn(this)

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

@ -93,10 +93,13 @@ val jar = tasks.named<Jar>("jar") {
this.duplicatesStrategy = DuplicatesStrategy.INCLUDE this.duplicatesStrategy = DuplicatesStrategy.INCLUDE
} }
val supportedGradleVersions = project.property("compose.tests.gradle.versions") val supportedGradleVersions = project.propertyList("compose.tests.gradle.versions")
.toString().split(",") val supportedAgpVersions = project.propertyList("compose.tests.agp.versions")
fun Project.propertyList(name: String) =
project.property(name).toString()
.split(",")
.map { it.trim() } .map { it.trim() }
.map { GradleVersion.version(it) }
val gradleTestsPattern = "org.jetbrains.compose.test.tests.integration.*" val gradleTestsPattern = "org.jetbrains.compose.test.tests.integration.*"
@ -151,17 +154,30 @@ for (jdkVersion in jdkVersionsForTests) {
} }
for (gradleVersion in supportedGradleVersions) { for (gradleVersion in supportedGradleVersions) {
tasks.registerVerificationTask<Test>("testGradle-${gradleVersion.version}") { for (agpVersion in supportedAgpVersions) {
tasks.registerVerificationTask<Test>("test-Gradle(${gradleVersion})-Agp($agpVersion)") {
classpath = tasks.test.get().classpath classpath = tasks.test.get().classpath
filter { includeTestsMatching(gradleTestsPattern) }
dependsOn(downloadJdksForTests) 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.test.jdks.root", jdkForTestsRoot.absolutePath)
if (gradleVersion >= GradleVersion.version("7.6")) { systemProperty("compose.tests.gradle.version", gradleVersion)
systemProperty("compose.tests.gradle.configuration.cache", "true") systemProperty("compose.tests.agp.version", agpVersion)
} systemProperty(
systemProperty("compose.tests.gradle.version", gradleVersion.version) "compose.tests.gradle.configuration.cache",
filter { GradleVersion.version(gradleVersion) >= GradleVersion.version("8.0")
includeTestsMatching(gradleTestsPattern) )
} }
} }
} }

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 java.util.concurrent.atomic.AtomicInteger
import kotlin.concurrent.thread import kotlin.concurrent.thread
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import java.io.File import java.io.File
class GradlePluginTest : GradlePluginTestBase() { 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 @Test
fun iosResources() { fun iosResources() {
Assumptions.assumeTrue(currentOS == OS.MacOS) Assumptions.assumeTrue(currentOS == OS.MacOS)
val iosTestEnv = iosTestEnv() val iosTestEnv = iosTestEnv()
val testEnv = defaultTestEnvironment.copy( val testEnv = defaultTestEnvironment.copy(
useGradleConfigurationCache = TestProperties.gradleBaseVersionForTests.isAtLeastGradle8,
additionalEnvVars = iosTestEnv.envVars additionalEnvVars = iosTestEnv.envVars
) )
with(testProject(TestProjects.iosResources, testEnv)) { with(TestProject(TestProjects.iosResources, testEnv)) {
gradle(":embedAndSignAppleFrameworkForXcode", "--dry-run").checks { gradle(":embedAndSignAppleFrameworkForXcode", "--dry-run").checks {
// This test is not intended to actually run embedAndSignAppleFrameworkForXcode. // This test is not intended to actually run embedAndSignAppleFrameworkForXcode.
// Instead, it should check that embedAndSign depends on syncComposeResources using dry run // Instead, it should check that embedAndSign depends on syncComposeResources using dry run
@ -96,11 +91,7 @@ class GradlePluginTest : GradlePluginTestBase() {
@Test @Test
fun iosTestResources() { fun iosTestResources() {
Assumptions.assumeTrue(currentOS == OS.MacOS) Assumptions.assumeTrue(currentOS == OS.MacOS)
val testEnv = defaultTestEnvironment.copy( with(testProject(TestProjects.iosResources)) {
useGradleConfigurationCache = TestProperties.gradleBaseVersionForTests.isAtLeastGradle8
)
with(testProject(TestProjects.iosResources, testEnv)) {
gradle(":linkDebugTestIosX64", "--dry-run").checks { gradle(":linkDebugTestIosX64", "--dry-run").checks {
check.taskSkipped(":copyTestComposeResourcesForIosX64") check.taskSkipped(":copyTestComposeResourcesForIosX64")
check.taskSkipped(":linkDebugTestIosX64") check.taskSkipped(":linkDebugTestIosX64")
@ -117,7 +108,6 @@ class GradlePluginTest : GradlePluginTestBase() {
Assumptions.assumeTrue(currentOS == OS.MacOS) Assumptions.assumeTrue(currentOS == OS.MacOS)
val iosTestEnv = iosTestEnv() val iosTestEnv = iosTestEnv()
val testEnv = defaultTestEnvironment.copy( val testEnv = defaultTestEnvironment.copy(
useGradleConfigurationCache = TestProperties.gradleBaseVersionForTests.isAtLeastGradle8,
additionalEnvVars = iosTestEnv.envVars additionalEnvVars = iosTestEnv.envVars
) )
with(testProject(TestProjects.iosMokoResources, testEnv)) { with(testProject(TestProjects.iosMokoResources, testEnv)) {
@ -138,11 +128,6 @@ class GradlePluginTest : GradlePluginTestBase() {
@Test @Test
fun nativeCacheKind() { fun nativeCacheKind() {
Assumptions.assumeTrue(currentOS == OS.MacOS) Assumptions.assumeTrue(currentOS == OS.MacOS)
fun nativeCacheKindProject(kotlinVersion: String) = testProject(
TestProjects.nativeCacheKind,
defaultTestEnvironment.copy(kotlinVersion = kotlinVersion, useGradleConfigurationCache = false)
)
val task = if (currentArch == Arch.X64) { val task = if (currentArch == Arch.X64) {
":subproject:linkDebugFrameworkIosX64" ":subproject:linkDebugFrameworkIosX64"
} else { } else {
@ -153,11 +138,14 @@ class GradlePluginTest : GradlePluginTestBase() {
// the compiler crashed (older k/native doesn't support libs built using newer k/native): // 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 // 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 (kotlinVersionNumbers(defaultTestEnvironment.kotlinVersion) >= KotlinVersion(1, 9, 20)) {
if (defaultKotlinVersion >= KotlinVersion(1, 9, 20)) {
testWorkDir.deleteRecursively() testWorkDir.deleteRecursively()
testWorkDir.mkdirs() testWorkDir.mkdirs()
with(nativeCacheKindProject(TestKotlinVersions.Default) ) { val project = TestProject(
TestProjects.nativeCacheKind,
defaultTestEnvironment.copy(useGradleConfigurationCache = false)
)
with(project) {
gradle(task, "--info").checks { gradle(task, "--info").checks {
check.taskSuccessful(task) check.taskSuccessful(task)
check.logContains("-Xauto-cache-from=") check.logContains("-Xauto-cache-from=")
@ -220,7 +208,7 @@ class GradlePluginTest : GradlePluginTestBase() {
} }
} }
testKotlinVersion(TestKotlinVersions.v1_9_21) testKotlinVersion("1.9.21")
} }
@Test @Test
@ -251,7 +239,7 @@ class GradlePluginTest : GradlePluginTestBase() {
@Test @Test
fun newAndroidTarget() { fun newAndroidTarget() {
Assumptions.assumeTrue(TestProperties.gradleBaseVersionForTests >= GradleVersion.version("8.0.0")) Assumptions.assumeTrue(defaultTestEnvironment.parsedGradleVersion >= GradleVersion.version("8.0.0"))
with(testProject(TestProjects.newAndroidTarget)) { with(testProject(TestProjects.newAndroidTarget)) {
gradle("build", "--dry-run").checks { 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 -> commonResourcesFiles.forEach { res ->
if (res == "font/emptyFont.otf") { if (res == "font/emptyFont.otf") {
//android fonts should be only in assets //android fonts should be only in assets
assertNull(zip.getEntry(res)) assertNull(zip.getEntry(res), "file = '$res'")
} else { } 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") val platformTxt = zip.getEntry("files/platform.txt")
assertNotNull(platformTxt) assertNotNull(platformTxt, "file = 'files/platform.txt'")
val text = zip.getInputStream(platformTxt).readBytes().decodeToString() val text = zip.getInputStream(platformTxt).readBytes().decodeToString()
assertEquals("android $flavor-$type", text) 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 package org.jetbrains.compose.test.utils
import org.junit.jupiter.api.DisplayNameGenerator import org.junit.jupiter.api.DisplayNameGenerator
import java.lang.reflect.Method
class GradleTestNameGenerator : DisplayNameGenerator.Standard() { class GradleTestNameGenerator : DisplayNameGenerator.Standard() {
private val gradleVersion = TestProperties.gradleVersionForTests?.let { "[Gradle '$it']" } ?: ""
override fun generateDisplayNameForClass(testClass: Class<*>?): String = override fun generateDisplayNameForMethod(testClass: Class<*>, testMethod: Method) =
super.generateDisplayNameForClass(testClass) + gradleVersion 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.testkit.runner.GradleRunner
import org.gradle.util.GradleVersion import org.gradle.util.GradleVersion
import org.jetbrains.compose.desktop.application.internal.ComposeProperties import org.jetbrains.compose.desktop.application.internal.ComposeProperties
import org.junit.jupiter.params.provider.Arguments
import java.io.File import java.io.File
import java.util.Properties import java.util.Properties
import java.util.stream.Stream
data class TestEnvironment( data class TestEnvironment(
val workingDir: File, val workingDir: File,
val kotlinVersion: String = TestKotlinVersions.Default, val kotlinVersion: String = TestProperties.composeCompilerCompatibleKotlinVersion,
val agpVersion: String = "7.3.1", val gradleVersion: String = TestProperties.gradleVersion,
val agpVersion: String = TestProperties.agpVersion,
val composeGradlePluginVersion: String = TestProperties.composeGradlePluginVersion, val composeGradlePluginVersion: String = TestProperties.composeGradlePluginVersion,
val mokoResourcesPluginVersion: String = "0.23.0", val mokoResourcesPluginVersion: String = "0.23.0",
val composeCompilerPlugin: String? = null, val composeCompilerPlugin: String? = null,
@ -42,6 +45,8 @@ data class TestEnvironment(
} }
file.writeText(content) file.writeText(content)
} }
val parsedGradleVersion: GradleVersion = GradleVersion.version(gradleVersion)
} }
private val testJdks = TestProperties private val testJdks = TestProperties
@ -57,7 +62,7 @@ class TestProject(
"--stacktrace", "--stacktrace",
"--init-script", testProjectsRootDir.resolve("init.gradle").absolutePath, "--init-script", testProjectsRootDir.resolve("init.gradle").absolutePath,
"-P${ComposeProperties.VERBOSE}=${testEnvironment.composeVerbose}", "-P${ComposeProperties.VERBOSE}=${testEnvironment.composeVerbose}",
if (GradleVersion.version(TestProperties.gradleVersionForTests).baseVersion < GradleVersion.version("8.0")) { if (testEnvironment.parsedGradleVersion < GradleVersion.version("8.0")) {
null null
} else { } else {
"-Porg.gradle.java.installations.paths=${testJdks.joinToString(",")}" "-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 { private inline fun withGradleRunner(args: Array<out String>, runnerFn: GradleRunner.() -> BuildResult): BuildResult {
if (testEnvironment.useGradleConfigurationCache) { 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. // Gradle 7.* does not use the configuration cache in the same build.
// In other words, if cache misses, Gradle performs configuration, // In other words, if cache misses, Gradle performs configuration,
// but does not, use the serialized task graph. // but does not, use the serialized task graph.
@ -123,7 +128,7 @@ class TestProject(
} }
return GradleRunner.create().apply { return GradleRunner.create().apply {
withGradleVersion(TestProperties.gradleVersionForTests) withGradleVersion(testEnvironment.gradleVersion)
withProjectDir(testEnvironment.workingDir) withProjectDir(testEnvironment.workingDir)
withArguments(allArgs) withArguments(allArgs)
if (testEnvironment.additionalEnvVars.isNotEmpty()) { 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 package org.jetbrains.compose.test.utils
import org.gradle.util.GradleVersion
import java.io.File import java.io.File
private const val COMPOSE_TESTS_GRADLE_VERSION_PROPERTY = "compose.tests.gradle.version"
object TestProperties { object TestProperties {
val composeCompilerVersion: String val composeCompilerVersion: String
get() = notNullSystemProperty("compose.tests.compiler.version") get() = notNullSystemProperty("compose.tests.compiler.version")
@ -23,12 +20,11 @@ object TestProperties {
val composeGradlePluginVersion: String val composeGradlePluginVersion: String
get() = notNullSystemProperty("compose.tests.compose.gradle.plugin.version") get() = notNullSystemProperty("compose.tests.compose.gradle.plugin.version")
val gradleVersionForTests: String val gradleVersion: String
get() = System.getProperty(COMPOSE_TESTS_GRADLE_VERSION_PROPERTY) get() = notNullSystemProperty("compose.tests.gradle.version")
?: error("System property '$COMPOSE_TESTS_GRADLE_VERSION_PROPERTY' is not set")
val gradleBaseVersionForTests: GradleVersion val agpVersion: String
get() = GradleVersion.version(gradleVersionForTests).baseVersion get() = notNullSystemProperty("compose.tests.agp.version")
val gradleConfigurationCache: Boolean val gradleConfigurationCache: Boolean
get() = System.getProperty("compose.tests.gradle.configuration.cache") == "true" 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 { android {
namespace = "org.jetbrains.compose.testapp"
compileSdk = 31 compileSdk = 31
defaultConfig { 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 compose.tests.js.compiler.compatible.kotlin.version=1.9.22
# __SUPPORTED_GRADLE_VERSIONS__ # __SUPPORTED_GRADLE_VERSIONS__
# Don't forget to edit versions in .github/workflows/gradle-plugin.yml as well # 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.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, # A version of Gradle plugin, that will be published,
# unless overridden by COMPOSE_GRADLE_PLUGIN_VERSION env var. # unless overridden by COMPOSE_GRADLE_PLUGIN_VERSION env var.

Loading…
Cancel
Save