Skip to content

Commit

Permalink
Add gradle "8.6" and AGP "7.3.1", "8.2.2" to the gradle plugin integr…
Browse files Browse the repository at this point in the history
…ation tests (#4309)
  • Loading branch information
terrakok authored and igordmn committed Mar 5, 2024
1 parent f683673 commit e9c11b0
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/gradle-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions gradle-plugins/buildSrc/src/main/kotlin/gradleUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
46 changes: 31 additions & 15 deletions gradle-plugins/compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"

Expand Down Expand Up @@ -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")
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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)) {
Expand All @@ -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 {
Expand All @@ -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=")
Expand Down Expand Up @@ -220,7 +208,7 @@ class GradlePluginTest : GradlePluginTestBase() {
}
}

testKotlinVersion(TestKotlinVersions.v1_9_21)
testKotlinVersion("1.9.21")
}

@Test
Expand Down Expand Up @@ -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 {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,6 +45,8 @@ data class TestEnvironment(
}
file.writeText(content)
}

val parsedGradleVersion: GradleVersion = GradleVersion.version(gradleVersion)
}

private val testJdks = TestProperties
Expand All @@ -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(",")}"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ kotlin {
}

android {
namespace = "org.jetbrains.compose.testapp"
compileSdk = 31

defaultConfig {
Expand Down
7 changes: 7 additions & 0 deletions gradle-plugins/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e9c11b0

Please sign in to comment.