Browse Source

Allow to use Compose on multiple Kotlin versions (#2366)

JS target supports a lower version (1.7.10), because we have a bug in Koltin 1.7.20

Compose 1.2.0 will support:

1.7.20 and 1.7.10 for Android and Desktop
1.7.10 for JS
We will release the new patchset (1.2.1) with 1.7.2X support for JS later
pull/2411/head
Igor Demin 2 years ago committed by GitHub
parent
commit
3996233b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      README.md
  2. 19
      VERSIONING.md
  3. 3
      examples/validateExamples.sh
  4. 24
      examples/validateExamplesWithJs.sh
  5. 4
      gradle-plugins/buildSrc/src/main/kotlin/BuildProperties.kt
  6. 1
      gradle-plugins/compose/build.gradle.kts
  7. 19
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerCompatability.kt
  8. 10
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerKotlinSupportPlugin.kt
  9. 77
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/ComposeCompilerArtifactProvider.kt
  10. 9
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
  11. 56
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/KotlinCompatabilityTest.kt
  12. 26
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/unit/ComposeCompilerArtifactProviderTest.kt
  13. 2
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/GradlePluginTestBase.kt
  14. 7
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestKotlinVersions.kt
  15. 4
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt
  16. 7
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProperties.kt
  17. 13
      gradle-plugins/gradle.properties
  18. 47
      tutorials/checker/build.gradle.kts

12
README.md

@ -4,10 +4,9 @@
# Compose Multiplatform, by JetBrains # Compose Multiplatform, by JetBrains
![](artwork/readme/apps.png) ![](artwork/readme/apps.png)
Compose Kotlin UI framework port for desktop platforms (macOS, Linux, Windows) and Web, components outside of the core Compose repository Compose Kotlin UI framework port for desktop platforms (macOS, Linux, Windows) and Web, components outside of the core [Compose repository](https://android.googlesource.com/platform/frameworks/support).
at https://android.googlesource.com/platform/frameworks/support.
Preview functionality (check your application UI without building/running it) for desktop platforms is available via IDEA plugin (https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support). Preview functionality (check your application UI without building/running it) for desktop platforms is available via [IDEA plugin](https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support).
## Tutorials ## Tutorials
### Compose for Desktop ### Compose for Desktop
@ -70,6 +69,9 @@ Note that when you use Compose Multiplatform, you setup your project differently
* [LWJGL integration](experimental/lwjgl-integration) - An example showing how to integrate Compose with [LWJGL](https://www.lwjgl.org) * [LWJGL integration](experimental/lwjgl-integration) - An example showing how to integrate Compose with [LWJGL](https://www.lwjgl.org)
* [CLI example](experimental/build_from_cli) - An example showing how to build Compose without Gradle * [CLI example](experimental/build_from_cli) - An example showing how to build Compose without Gradle
## Getting latest version of Compose Multiplatform ## ## Versions ##
See https://github.com/JetBrains/compose-jb/releases/latest for the latest stable release or https://github.com/JetBrains/compose-jb/releases for all stable and dev releases. * [The latest stable release](https://github.com/JetBrains/compose-jb/releases/latest)
* [The latest dev release](https://github.com/JetBrains/compose-jb/releases)
* [Compatability and versioning overview](VERSIONING.md)
* [Changelog](CHANGELOG.md)

19
FEATURES.md → VERSIONING.md

@ -21,12 +21,13 @@ Knowing issues on older versions:
### Kotlin compatibility ### Kotlin compatibility
Compose version | Kotlin version A new version of Kotlin may be not supported immediately after its release. But after some time we will release a version of Compose Multiplatform
--- | --- that supports it.
1.0.0+ | 1.5.31 Starting from 1.2.0, Compose Multiplatform supports multiple versions of Kotlin.
1.0.1-rc2+ | 1.6.10
Kotlin version | Minimal Compose version | Notes
--- | --- | ---
### Gradle plugin compatibility 1.5.31 | 1.0.0
1.6.20 | 1.1.1
* 1.0.0 works with Gradle 6.7 or later (7.2 is the latest tested version). 1.7.10 | 1.2.0
1.7.20 | 1.2.0 | JS is not supported (will be fixed in the next versions)

3
examples/validateExamples.sh

@ -25,7 +25,4 @@ runGradle issues package
runGradle notepad package runGradle notepad package
runGradle todoapp-lite package runGradle todoapp-lite package
runGradle visual-effects package runGradle visual-effects package
runGradle web-compose-bird build
runGradle web-landing build
runGradle web-with-react build
runGradle widgets-gallery package runGradle widgets-gallery package

24
examples/validateExamplesWithJs.sh

@ -0,0 +1,24 @@
#!/bin/bash
# Script to build most of the examples, to verify if they can compile.
# Don't add examples, which don't depend on maven.pkg.jetbrains.space, because they won't be able to compile.
set -euo pipefail
if [ "$#" -ne 2 ]; then
echo "Specify Compose and Kotlin version. For example: ./validateExamplesWithJs.sh 1.1.1 1.6.10"
exit 1
fi
COMPOSE_VERSION=$1
KOTLIN_VERSION=$2
runGradle() {
pushd $1
./gradlew $2 -Pcompose.version=$COMPOSE_VERSION -Pkotlin.version=$KOTLIN_VERSION
popd
}
runGradle web-compose-bird build
runGradle web-landing build
runGradle web-with-react build

4
gradle-plugins/buildSrc/src/main/kotlin/BuildProperties.kt

@ -15,10 +15,6 @@ object BuildProperties {
fun composeVersion(project: Project): String = fun composeVersion(project: Project): String =
System.getenv("COMPOSE_GRADLE_PLUGIN_COMPOSE_VERSION") System.getenv("COMPOSE_GRADLE_PLUGIN_COMPOSE_VERSION")
?: project.findProperty("compose.version") as String ?: project.findProperty("compose.version") as String
fun composeCompilerVersion(project: Project): String =
project.findProperty("compose.compiler.version") as String
fun composeCompilerCompatibleKotlinVersion(project: Project): String =
project.findProperty("compose.compiler.compatible.kotlin.version") as String
fun testsAndroidxCompilerVersion(project: Project): String = fun testsAndroidxCompilerVersion(project: Project): String =
project.findProperty("compose.tests.androidx.compiler.version") as String project.findProperty("compose.tests.androidx.compiler.version") as String
fun testsAndroidxCompilerCompatibleVersion(project: Project): String = fun testsAndroidxCompilerCompatibleVersion(project: Project): String =

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

@ -29,7 +29,6 @@ val buildConfig = tasks.register("buildConfig", GenerateBuildConfig::class.java)
classFqName.set("org.jetbrains.compose.ComposeBuildConfig") classFqName.set("org.jetbrains.compose.ComposeBuildConfig")
generatedOutputDir.set(buildConfigDir) generatedOutputDir.set(buildConfigDir)
fieldsToGenerate.put("composeVersion", BuildProperties.composeVersion(project)) fieldsToGenerate.put("composeVersion", BuildProperties.composeVersion(project))
fieldsToGenerate.put("composeCompilerVersion", BuildProperties.composeCompilerVersion(project))
fieldsToGenerate.put("composeGradlePluginVersion", BuildProperties.deployVersion(project)) fieldsToGenerate.put("composeGradlePluginVersion", BuildProperties.deployVersion(project))
} }
tasks.named("compileKotlin") { tasks.named("compileKotlin") {

19
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerCompatability.kt

@ -0,0 +1,19 @@
package org.jetbrains.compose
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
internal object ComposeCompilerCompatability {
fun compilerVersionFor(kotlinVersion: String): ComposeCompilerVersion? = when (kotlinVersion) {
"1.7.10" -> ComposeCompilerVersion("1.3.0-alpha01")
"1.7.20" -> ComposeCompilerVersion(
"1.3.2-alpha01",
unsupportedPlatforms = setOf(KotlinPlatformType.js)
)
else -> null
}
}
internal data class ComposeCompilerVersion(
val version: String,
val unsupportedPlatforms: Set<KotlinPlatformType> = emptySet()
)

10
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerKotlinSupportPlugin.kt

@ -13,13 +13,18 @@ import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin { class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin {
private var composeCompilerArtifactProvider = ComposeCompilerArtifactProvider { null } private lateinit var composeCompilerArtifactProvider: ComposeCompilerArtifactProvider
override fun apply(target: Project) { override fun apply(target: Project) {
super.apply(target) super.apply(target)
target.plugins.withType(ComposePlugin::class.java) { target.plugins.withType(ComposePlugin::class.java) {
val composeExt = target.extensions.getByType(ComposeExtension::class.java) val composeExt = target.extensions.getByType(ComposeExtension::class.java)
composeCompilerArtifactProvider = ComposeCompilerArtifactProvider { composeExt.kotlinCompilerPlugin.orNull }
composeCompilerArtifactProvider = ComposeCompilerArtifactProvider(
kotlinVersion = target.getKotlinPluginVersion()
) {
composeExt.kotlinCompilerPlugin.orNull
}
} }
} }
@ -52,6 +57,7 @@ class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin {
override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> { override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> {
val target = kotlinCompilation.target val target = kotlinCompilation.target
composeCompilerArtifactProvider.checkTargetSupported(target)
return target.project.provider { return target.project.provider {
platformPluginOptions[target.platformType] ?: emptyList() platformPluginOptions[target.platformType] ?: emptyList()
} }

77
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/ComposeCompilerArtifactProvider.kt

@ -5,33 +5,67 @@
package org.jetbrains.compose.internal package org.jetbrains.compose.internal
import org.jetbrains.compose.ComposeBuildConfig import org.jetbrains.compose.ComposeCompilerCompatability
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
internal class ComposeCompilerArtifactProvider(private val customPluginString: () -> String?) { private const val KOTLIN_COMPATABILITY_LINK =
"https://github.com/JetBrains/compose-jb/blob/master/VERSIONING.md#kotlin-compatibility"
internal class ComposeCompilerArtifactProvider(
private val kotlinVersion: String,
customPluginString: () -> String?
) {
fun checkTargetSupported(target: KotlinTarget) {
require(!unsupportedPlatforms.contains(target.platformType)) {
"This version of Compose Multiplatform doesn't support Kotlin " +
"$kotlinVersion for ${target.platformType} target. " +
"Please see $KOTLIN_COMPATABILITY_LINK " +
"to know the latest supported version of Kotlin."
}
}
private var unsupportedPlatforms: Set<KotlinPlatformType> = emptySet()
val compilerArtifact: SubpluginArtifact val compilerArtifact: SubpluginArtifact
get() {
val customPlugin = customPluginString() init {
val customCoordinates = customPlugin?.split(":") val customPlugin = customPluginString()
return when (customCoordinates?.size) { val customCoordinates = customPlugin?.split(":")
null -> DefaultCompiler.pluginArtifact when (customCoordinates?.size) {
1 -> { null -> {
val customVersion = customCoordinates[0] val version = requireNotNull(
check(customVersion.isNotBlank()) { "'compose.kotlinCompilerPlugin' cannot be blank!" } ComposeCompilerCompatability.compilerVersionFor(kotlinVersion)
DefaultCompiler.pluginArtifact.copy(version = customVersion) ) {
"This version of Compose Multiplatform doesn't support Kotlin " +
"$kotlinVersion. " +
"Please see $KOTLIN_COMPATABILITY_LINK " +
"to know the latest supported version of Kotlin."
} }
3 -> DefaultCompiler.pluginArtifact.copy(
groupId = customCoordinates[0], compilerArtifact = DefaultCompiler.pluginArtifact(
artifactId = customCoordinates[1], version = version.version
version = customCoordinates[2]
) )
else -> error(""" unsupportedPlatforms = version.unsupportedPlatforms
}
1 -> {
val customVersion = customCoordinates[0]
check(customVersion.isNotBlank()) { "'compose.kotlinCompilerPlugin' cannot be blank!" }
compilerArtifact = DefaultCompiler.pluginArtifact(version = customVersion)
}
3 -> compilerArtifact = DefaultCompiler.pluginArtifact(
version = customCoordinates[2],
groupId = customCoordinates[0],
artifactId = customCoordinates[1],
)
else -> error("""
Illegal format of 'compose.kotlinCompilerPlugin' property. Illegal format of 'compose.kotlinCompilerPlugin' property.
Expected format: either '<VERSION>' or '<GROUP_ID>:<ARTIFACT_ID>:<VERSION>' Expected format: either '<VERSION>' or '<GROUP_ID>:<ARTIFACT_ID>:<VERSION>'
Actual value: '$customPlugin' Actual value: '$customPlugin'
""".trimIndent()) """.trimIndent())
}
} }
}
val compilerHostedArtifact: SubpluginArtifact val compilerHostedArtifact: SubpluginArtifact
get() = compilerArtifact.run { get() = compilerArtifact.run {
@ -47,10 +81,13 @@ internal class ComposeCompilerArtifactProvider(private val customPluginString: (
const val GROUP_ID = "org.jetbrains.compose.compiler" const val GROUP_ID = "org.jetbrains.compose.compiler"
const val ARTIFACT_ID = "compiler" const val ARTIFACT_ID = "compiler"
const val HOSTED_ARTIFACT_ID = "compiler-hosted" const val HOSTED_ARTIFACT_ID = "compiler-hosted"
const val VERSION = ComposeBuildConfig.composeCompilerVersion
val pluginArtifact: SubpluginArtifact fun pluginArtifact(
get() = SubpluginArtifact(groupId = GROUP_ID, artifactId = ARTIFACT_ID, version = VERSION) version: String,
groupId: String = GROUP_ID,
artifactId: String = ARTIFACT_ID,
): SubpluginArtifact =
SubpluginArtifact(groupId = groupId, artifactId = artifactId, version = version)
} }
} }

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

@ -22,7 +22,14 @@ import org.junit.jupiter.api.Test
class GradlePluginTest : GradlePluginTestBase() { class GradlePluginTest : GradlePluginTestBase() {
@Test @Test
fun jsMppIsNotBroken() = fun jsMppIsNotBroken() =
with(testProject(TestProjects.jsMpp)) { with(
testProject(
TestProjects.jsMpp,
testEnvironment = defaultTestEnvironment.copy(
kotlinVersion = TestProperties.composeJsCompilerCompatibleKotlinVersion
)
)
) {
gradle(":compileKotlinJs").build().checks { check -> gradle(":compileKotlinJs").build().checks { check ->
check.taskOutcome(":compileKotlinJs", TaskOutcome.SUCCESS) check.taskOutcome(":compileKotlinJs", TaskOutcome.SUCCESS)
} }

56
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/KotlinCompatabilityTest.kt

@ -0,0 +1,56 @@
/*
* 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.tests.integration
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.UnexpectedBuildFailure
import org.jetbrains.compose.test.utils.GradlePluginTestBase
import org.jetbrains.compose.test.utils.TestProjects
import org.jetbrains.compose.test.utils.checks
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
class KotlinCompatabilityTest : GradlePluginTestBase() {
@Test
fun testKotlinMpp_1_7_10() = testMpp("1.7.10")
@Test
fun testKotlinJsMpp_1_7_10() = testJsMpp("1.7.10")
@Test
fun testKotlinMpp_1_7_20() = testMpp("1.7.20")
@Test
fun testKotlinJsMpp_1_7_20() {
assertThrows<UnexpectedBuildFailure> {
testJsMpp("1.7.20")
}
}
private fun testMpp(kotlinVersion: String) = with(
testProject(
TestProjects.mpp,
testEnvironment = defaultTestEnvironment.copy(kotlinVersion = kotlinVersion)
)
) {
val logLine = "Kotlin MPP app is running!"
gradle("run").build().checks { check ->
check.taskOutcome(":run", TaskOutcome.SUCCESS)
check.logContains(logLine)
}
}
private fun testJsMpp(kotlinVersion: String) = with(
testProject(
TestProjects.jsMpp,
testEnvironment = defaultTestEnvironment.copy(kotlinVersion = kotlinVersion)
)
) {
gradle(":compileKotlinJs").build().checks { check ->
check.taskOutcome(":compileKotlinJs", TaskOutcome.SUCCESS)
}
}
}

26
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/unit/ComposeCompilerArtifactProviderTest.kt

@ -18,7 +18,7 @@ internal class ComposeCompilerArtifactProviderTest {
fun defaultCompilerArtifact() { fun defaultCompilerArtifact() {
assertArtifactEquals( assertArtifactEquals(
Expected.jbCompiler, Expected.jbCompiler,
Actual.compiler(null) Actual.compiler(null, TestProperties.composeCompilerCompatibleKotlinVersion)
) )
} }
@ -26,7 +26,7 @@ internal class ComposeCompilerArtifactProviderTest {
fun defaultCompilerHostedArtifact() { fun defaultCompilerHostedArtifact() {
assertArtifactEquals( assertArtifactEquals(
Expected.jbCompilerHosted, Expected.jbCompilerHosted,
Actual.compilerHosted(null) Actual.compilerHosted(null, TestProperties.composeCompilerCompatibleKotlinVersion)
) )
} }
@ -34,7 +34,7 @@ internal class ComposeCompilerArtifactProviderTest {
fun customVersion() { fun customVersion() {
assertArtifactEquals( assertArtifactEquals(
Expected.jbCompiler.copy(version = "10.20.30"), Expected.jbCompiler.copy(version = "10.20.30"),
Actual.compiler("10.20.30") Actual.compiler("10.20.30", TestProperties.composeCompilerCompatibleKotlinVersion)
) )
} }
@ -42,7 +42,10 @@ internal class ComposeCompilerArtifactProviderTest {
fun customCompiler() { fun customCompiler() {
assertArtifactEquals( assertArtifactEquals(
Expected.googleCompiler.copy(version = "1.3.1"), Expected.googleCompiler.copy(version = "1.3.1"),
Actual.compiler("androidx.compose.compiler:compiler:1.3.1") Actual.compiler(
"androidx.compose.compiler:compiler:1.3.1",
TestProperties.androidxCompilerCompatibleKotlinVersion
)
) )
} }
@ -51,7 +54,10 @@ internal class ComposeCompilerArtifactProviderTest {
// check that we don't replace artifactId for non-jb compiler // check that we don't replace artifactId for non-jb compiler
assertArtifactEquals( assertArtifactEquals(
Expected.googleCompiler.copy(version = "1.3.1"), Expected.googleCompiler.copy(version = "1.3.1"),
Actual.compilerHosted("androidx.compose.compiler:compiler:1.3.1") Actual.compilerHosted(
"androidx.compose.compiler:compiler:1.3.1",
TestProperties.composeCompilerCompatibleKotlinVersion
)
) )
} }
@ -64,7 +70,7 @@ internal class ComposeCompilerArtifactProviderTest {
private fun testIllegalCompiler(pluginString: String?) { private fun testIllegalCompiler(pluginString: String?) {
try { try {
Actual.compiler(pluginString) Actual.compiler(pluginString, "")
} catch (e: Exception) { } catch (e: Exception) {
return return
} }
@ -73,11 +79,11 @@ internal class ComposeCompilerArtifactProviderTest {
} }
object Actual { object Actual {
fun compiler(pluginString: String?) = fun compiler(pluginString: String?, kotlinVersion: String) =
ComposeCompilerArtifactProvider { pluginString }.compilerArtifact ComposeCompilerArtifactProvider(kotlinVersion) { pluginString }.compilerArtifact
fun compilerHosted(pluginString: String?) = fun compilerHosted(pluginString: String?, kotlinVersion: String) =
ComposeCompilerArtifactProvider { pluginString }.compilerHostedArtifact ComposeCompilerArtifactProvider(kotlinVersion) { pluginString }.compilerHostedArtifact
} }
object Expected { object Expected {

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

@ -17,7 +17,7 @@ abstract class GradlePluginTestBase {
val defaultAndroidxCompilerEnvironment: TestEnvironment val defaultAndroidxCompilerEnvironment: TestEnvironment
get() = defaultTestEnvironment.copy( get() = defaultTestEnvironment.copy(
kotlinVersion = TestKotlinVersion.AndroidxCompatible, kotlinVersion = TestKotlinVersions.AndroidxCompatible,
composeCompilerArtifact = "androidx.compose.compiler:compiler:${TestProperties.androidxCompilerVersion}" composeCompilerArtifact = "androidx.compose.compiler:compiler:${TestProperties.androidxCompilerVersion}"
) )

7
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestKotlinVersion.kt → gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestKotlinVersions.kt

@ -5,8 +5,7 @@
package org.jetbrains.compose.test.utils package org.jetbrains.compose.test.utils
@Suppress("EnumEntryName") object TestKotlinVersions {
enum class TestKotlinVersion(val versionString: String) { val Default = TestProperties.composeCompilerCompatibleKotlinVersion
Default(TestProperties.composeCompilerCompatibleKotlinVersion), val AndroidxCompatible = TestProperties.androidxCompilerCompatibleKotlinVersion
AndroidxCompatible(TestProperties.androidxCompilerCompatibleKotlinVersion)
} }

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

@ -11,7 +11,7 @@ import java.io.File
data class TestEnvironment( data class TestEnvironment(
val workingDir: File, val workingDir: File,
val kotlinVersion: TestKotlinVersion = TestKotlinVersion.Default, val kotlinVersion: String = TestKotlinVersions.Default,
val composeGradlePluginVersion: String = TestProperties.composeGradlePluginVersion, val composeGradlePluginVersion: String = TestProperties.composeGradlePluginVersion,
val composeCompilerArtifact: String? = null val composeCompilerArtifact: String? = null
) )
@ -41,7 +41,7 @@ class TestProject(
val origContent = orig.readText() val origContent = orig.readText()
var newContent = origContent var newContent = origContent
.replace("COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER", testEnvironment.composeGradlePluginVersion) .replace("COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER", testEnvironment.composeGradlePluginVersion)
.replace("KOTLIN_VERSION_PLACEHOLDER", testEnvironment.kotlinVersion.versionString) .replace("KOTLIN_VERSION_PLACEHOLDER", testEnvironment.kotlinVersion)
if (testEnvironment.composeCompilerArtifact != null) { if (testEnvironment.composeCompilerArtifact != null) {
newContent = newContent.replace("COMPOSE_COMPILER_ARTIFACT_PLACEHOLDER", testEnvironment.composeCompilerArtifact) newContent = newContent.replace("COMPOSE_COMPILER_ARTIFACT_PLACEHOLDER", testEnvironment.composeCompilerArtifact)
} }

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

@ -7,10 +7,13 @@ package org.jetbrains.compose.test.utils
object TestProperties { object TestProperties {
val composeCompilerVersion: String val composeCompilerVersion: String
get() = notNullSystemProperty("compose.compiler.version") get() = notNullSystemProperty("compose.tests.compiler.version")
val composeCompilerCompatibleKotlinVersion: String val composeCompilerCompatibleKotlinVersion: String
get() = notNullSystemProperty("compose.compiler.compatible.kotlin.version") get() = notNullSystemProperty("compose.tests.compiler.compatible.kotlin.version")
val composeJsCompilerCompatibleKotlinVersion: String
get() = notNullSystemProperty("compose.tests.js.compiler.compatible.kotlin.version")
val androidxCompilerVersion: String val androidxCompilerVersion: String
get() = notNullSystemProperty("compose.tests.androidx.compiler.version") get() = notNullSystemProperty("compose.tests.androidx.compiler.version")

13
gradle-plugins/gradle.properties

@ -1,13 +1,16 @@
org.gradle.parallel=true org.gradle.parallel=true
kotlin.code.style=official kotlin.code.style=official
# __LATEST_COMPOSE_RELEASE_VERSION__
# Default version of Compose Libraries used by Gradle plugin # Default version of Compose Libraries used by Gradle plugin
compose.version=1.2.0-beta02 compose.version=1.2.0-beta02
# Default version of Compose Compiler used by Gradle plugin # The latest version of Compose Compiler used by Gradle plugin. Used only in tests.
compose.compiler.version=1.3.2-alpha01 compose.tests.compiler.version=1.3.2-alpha01
# Default version of Kotlin compatible with compose.compiler.version # The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests.
compose.compiler.compatible.kotlin.version=1.7.20 compose.tests.compiler.compatible.kotlin.version=1.7.20
# The latest version of Kotlin compatible with compose.tests.compiler.version for JS target. Used only on CI.
compose.tests.js.compiler.compatible.kotlin.version=1.7.10
# Version of Compose Compiler published by Google.
# Used to check if our plugin is compatible with it.
# https://developer.android.com/jetpack/androidx/releases/compose-kotlin # https://developer.android.com/jetpack/androidx/releases/compose-kotlin
compose.tests.androidx.compiler.version=1.3.1 compose.tests.androidx.compiler.version=1.3.1
compose.tests.androidx.compiler.compatible.kotlin.version=1.7.10 compose.tests.androidx.compiler.compatible.kotlin.version=1.7.10

47
tutorials/checker/build.gradle.kts

@ -70,7 +70,7 @@ fun maybeFail(tutorial: String, message: String) {
} }
@OptIn(ExperimentalStdlibApi::class) @OptIn(ExperimentalStdlibApi::class)
fun checkDirs(dirs: List<String>, template: String, buildCmd: String = "build") { fun checkDirs(dirs: List<String>, template: String, buildCmd: String, kotlinVersion: String?) {
val snippets = findSnippets(dirs) val snippets = findSnippets(dirs)
snippets.forEachIndexed { index, snippet -> snippets.forEachIndexed { index, snippet ->
println("process snippet $index at ${snippet.file}:${snippet.lineNumber} with $template") println("process snippet $index at ${snippet.file}:${snippet.lineNumber} with $template")
@ -86,7 +86,7 @@ fun checkDirs(dirs: List<String>, template: String, buildCmd: String = "build")
add(buildCmd) add(buildCmd)
project.findProperty("kotlin.version")?.also { kotlinVersion?.also {
add("-Pkotlin.version=$it") add("-Pkotlin.version=$it")
} }
project.findProperty("compose.version")?.also { project.findProperty("compose.version")?.also {
@ -110,7 +110,7 @@ fun checkDirs(dirs: List<String>, template: String, buildCmd: String = "build")
// NOTICE: currently we use a bit hacky approach, when "```kotlin" marks code that shall be checked, while "``` kotlin" // NOTICE: currently we use a bit hacky approach, when "```kotlin" marks code that shall be checked, while "``` kotlin"
// with whitespace marks code that shall not be checked. // with whitespace marks code that shall not be checked.
tasks.register("check") { tasks.register("check") {
val checks = CheckSpec.createCheckSpecs( val checks = createCheckSpecs(
checkTargets = (project.property("CHECK_TARGET")?.toString() ?: "all").toLowerCase() checkTargets = (project.property("CHECK_TARGET")?.toString() ?: "all").toLowerCase()
) )
@ -129,29 +129,36 @@ tasks.register("check") {
checkDirs( checkDirs(
dirs = subdirs.map { "${check.dir}/$it" }, dirs = subdirs.map { "${check.dir}/$it" },
template = check.template, template = check.template,
buildCmd = check.gradleCmd buildCmd = check.gradleCmd,
kotlinVersion = check.kotlinVersion
) )
} }
} }
} }
data class CheckSpec(
val gradleCmd: String,
val dir: String,
val template: String
) {
companion object { fun createCheckSpecs(checkTargets: String = "all"): List<CheckSpec> {
fun desktop() = CheckSpec(gradleCmd = "build", dir = ".", template = "desktop-template") fun desktop() = CheckSpec(
fun web() = CheckSpec(gradleCmd = "compileKotlinJs", dir = "Web", template = "web-template") gradleCmd = "build", dir = ".", template = "desktop-template",
fun all() = listOf(desktop(), web()) kotlinVersion = project.findProperty("kotlin.version")?.toString()
)
fun web() = CheckSpec(
gradleCmd = "compileKotlinJs", dir = "Web", template = "web-template",
kotlinVersion = project.findProperty("kotlin.js.version")?.toString() ?:
project.findProperty("kotlin.version")?.toString()
)
fun all() = listOf(desktop(), web())
fun createCheckSpecs(checkTargets: String = "all"): List<CheckSpec> { return when (checkTargets) {
return when (checkTargets) { "web" -> listOf(web())
"web" -> listOf(web()) "desktop" -> listOf(desktop())
"desktop" -> listOf(desktop()) else -> all()
else -> all()
}
}
} }
} }
data class CheckSpec(
val gradleCmd: String,
val dir: String,
val template: String,
val kotlinVersion: String?
)
Loading…
Cancel
Save