Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kotlinCompilerPlugin property #2396

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jetbrains.compose.internal

import org.jetbrains.compose.ComposeCompilerCompatability
import org.jetbrains.compose.internal.ComposeCompilerArtifactProvider.DefaultCompiler.pluginArtifact
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
Expand All @@ -15,7 +16,7 @@ private const val KOTLIN_COMPATABILITY_LINK =

internal class ComposeCompilerArtifactProvider(
private val kotlinVersion: String,
customPluginString: () -> String?
private val customPluginString: () -> String?
) {
fun checkTargetSupported(target: KotlinTarget) {
require(!unsupportedPlatforms.contains(target.platformType)) {
Expand All @@ -26,35 +27,28 @@ internal class ComposeCompilerArtifactProvider(
}
}

private var unsupportedPlatforms: Set<KotlinPlatformType> = emptySet()

val compilerArtifact: SubpluginArtifact
private val autoCompilerVersion by lazy {
requireNotNull(
ComposeCompilerCompatability.compilerVersionFor(kotlinVersion)
) {
"This version of Compose Multiplatform doesn't support Kotlin " +
"$kotlinVersion. " +
"Please see $KOTLIN_COMPATABILITY_LINK " +
"to know the latest supported version of Kotlin."
}
}

init {
private val customCompilerArtifact: SubpluginArtifact? by lazy {
val customPlugin = customPluginString()
val customCoordinates = customPlugin?.split(":")
when (customCoordinates?.size) {
null -> {
val version = requireNotNull(
ComposeCompilerCompatability.compilerVersionFor(kotlinVersion)
) {
"This version of Compose Multiplatform doesn't support Kotlin " +
"$kotlinVersion. " +
"Please see $KOTLIN_COMPATABILITY_LINK " +
"to know the latest supported version of Kotlin."
}

compilerArtifact = DefaultCompiler.pluginArtifact(
version = version.version
)
unsupportedPlatforms = version.unsupportedPlatforms
}
null -> null
1 -> {
val customVersion = customCoordinates[0]
check(customVersion.isNotBlank()) { "'compose.kotlinCompilerPlugin' cannot be blank!" }
compilerArtifact = DefaultCompiler.pluginArtifact(version = customVersion)
pluginArtifact(version = customVersion)
}
3 -> compilerArtifact = DefaultCompiler.pluginArtifact(
3 -> pluginArtifact(
version = customCoordinates[2],
groupId = customCoordinates[0],
artifactId = customCoordinates[1],
Expand All @@ -67,6 +61,14 @@ internal class ComposeCompilerArtifactProvider(
}
}

private val unsupportedPlatforms: Set<KotlinPlatformType> by lazy {
if (customCompilerArtifact != null) emptySet() else autoCompilerVersion.unsupportedPlatforms
}

val compilerArtifact: SubpluginArtifact get() {
return customCompilerArtifact ?: pluginArtifact(version = autoCompilerVersion.version)
}

val compilerHostedArtifact: SubpluginArtifact
get() = compilerArtifact.run {
val newArtifactId =
Expand Down
4 changes: 2 additions & 2 deletions gradle-plugins/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ 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
compose.tests.androidx.compiler.version=1.3.1
compose.tests.androidx.compiler.compatible.kotlin.version=1.7.10
compose.tests.androidx.compiler.version=1.1.1
compose.tests.androidx.compiler.compatible.kotlin.version=1.6.10

# A version of Gradle plugin, that will be published,
# unless overridden by COMPOSE_GRADLE_PLUGIN_VERSION env var.
Expand Down