Browse Source

Don't apply Compose compiler plugin to JS and Native compilations

Resolves #352

The fix resolves the issue only for Kotlin compiler builds the following commit:
d023f09bd4

See also https://youtrack.jetbrains.com/issue/KT-45020
pull/501/head
Alexey Tsvetkov 4 years ago committed by Alexey Tsvetkov
parent
commit
76cccb93b9
  1. 23
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerKotlinSupportPlugin.kt
  2. 9
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt
  3. 23
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/GradlePluginTest.kt
  4. 10
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/GradlePluginTestBase.kt
  5. 8
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestKotlinVersion.kt
  6. 20
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProject.kt
  7. 1
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProjects.kt
  8. 3
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProperties.kt
  9. 33
      gradle-plugins/compose/src/test/test-projects/misc/jsMpp/build.gradle
  10. 12
      gradle-plugins/compose/src/test/test-projects/misc/jsMpp/settings.gradle
  11. 1
      gradle-plugins/compose/src/test/test-projects/misc/jsMpp/src/commonMain/kotlin/platform.kt
  12. 1
      gradle-plugins/compose/src/test/test-projects/misc/jsMpp/src/jsMain/kotlin/platform.kt
  13. 1
      gradle-plugins/compose/src/test/test-projects/misc/jsMpp/src/jvmMain/kotlin/platform.kt

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

@ -0,0 +1,23 @@
package org.jetbrains.compose
import org.gradle.api.provider.Provider
import org.jetbrains.kotlin.gradle.plugin.*
class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin {
override fun getCompilerPluginId(): String =
"org.jetbrains.compose"
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
val targetPlatform = kotlinCompilation.target.platformType
return targetPlatform != KotlinPlatformType.js
&& targetPlatform != KotlinPlatformType.native
}
override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> =
kotlinCompilation.target.project.provider { emptyList() }
override fun getPluginArtifact(): SubpluginArtifact =
SubpluginArtifact(
groupId = "org.jetbrains.compose.compiler", artifactId = "compiler", version = composeVersion
)
}

9
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt

@ -13,7 +13,7 @@ import org.jetbrains.compose.desktop.application.internal.currentTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
private val composeVersion get() = ComposeBuildConfig.composeVersion
internal val composeVersion get() = ComposeBuildConfig.composeVersion
class ComposePlugin : Plugin<Project> {
override fun apply(project: Project) {
@ -30,17 +30,14 @@ class ComposePlugin : Plugin<Project> {
}
}
project.pluginManager.apply(ComposeCompilerKotlinSupportPlugin::class.java)
project.afterEvaluate {
if (desktopExtension._isApplicationInitialized) {
// If application object was not accessed in a script,
// we want to avoid creating tasks like package, run, etc. to avoid conflicts with other plugins
configureApplicationImpl(project, desktopExtension.application)
}
project.dependencies.add(
"kotlinCompilerPluginClasspath",
"org.jetbrains.compose.compiler:compiler:$composeVersion"
)
}
fun ComponentModuleMetadataHandler.replaceAndroidx(original: String, replacement: String) {

23
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/GradlePluginTest.kt

@ -0,0 +1,23 @@
package org.jetbrains.compose
import org.gradle.testkit.runner.TaskOutcome
import org.jetbrains.compose.test.GradlePluginTestBase
import org.jetbrains.compose.test.TestKotlinVersion
import org.jetbrains.compose.test.TestProjects
import org.jetbrains.compose.test.checks
import org.junit.jupiter.api.Test
class GradlePluginTest : GradlePluginTestBase() {
@Test
fun jsMppIsNotBroken() =
with(
testProject(
TestProjects.jsMpp,
testEnvironment = defaultTestEnvironment.copy(kotlinVersion = TestKotlinVersion.V1_5_20_dev_3226)
)
) {
gradle(":compileKotlinJs").build().checks { check ->
check.taskOutcome(":compileKotlinJs", TaskOutcome.SUCCESS)
}
}
}

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

@ -7,6 +7,12 @@ abstract class GradlePluginTestBase {
@TempDir
lateinit var testWorkDir: File
fun testProject(name: String): TestProject =
TestProject(name, workingDir = testWorkDir)
val defaultTestEnvironment: TestEnvironment
get() = TestEnvironment(workingDir = testWorkDir)
fun testProject(
name: String,
testEnvironment: TestEnvironment = defaultTestEnvironment
): TestProject =
TestProject(name, testEnvironment = testEnvironment)
}

8
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestKotlinVersion.kt

@ -0,0 +1,8 @@
package org.jetbrains.compose.test
@Suppress("EnumEntryName")
enum class TestKotlinVersion(val versionString: String) {
// __KOTLIN_COMPOSE_VERSION__
Default("1.4.31"),
V1_5_20_dev_3226("1.5.20-dev-3226")
}

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

@ -4,9 +4,15 @@ import org.gradle.testkit.runner.GradleRunner
import org.jetbrains.compose.desktop.application.internal.ComposeProperties
import java.io.File
data class TestProject(
data class TestEnvironment(
val workingDir: File,
val kotlinVersion: TestKotlinVersion = TestKotlinVersion.Default,
val composeVersion: String = TestProperties.composeVersion
)
class TestProject(
private val name: String,
private val workingDir: File
private val testEnvironment: TestEnvironment
) {
private val additionalArgs = listOf(
"--stacktrace",
@ -20,14 +26,14 @@ data class TestProject(
for (orig in originalTestRoot.walk()) {
if (!orig.isFile) continue
val target = workingDir.resolve(orig.relativeTo(originalTestRoot))
val target = testEnvironment.workingDir.resolve(orig.relativeTo(originalTestRoot))
target.parentFile.mkdirs()
if (orig.name.endsWith(".gradle") || orig.name.endsWith(".gradle.kts")) {
val origContent = orig.readText()
val newContent = origContent
.replace("COMPOSE_VERSION_PLACEHOLDER", TestProperties.composeVersion)
.replace("KOTLIN_VERSION_PLACEHOLDER", TestProperties.kotlinVersion)
.replace("COMPOSE_VERSION_PLACEHOLDER", testEnvironment.composeVersion)
.replace("KOTLIN_VERSION_PLACEHOLDER", testEnvironment.kotlinVersion.versionString)
target.writeText(newContent)
} else {
orig.copyTo(target)
@ -38,7 +44,7 @@ data class TestProject(
fun gradle(vararg args: String): GradleRunner =
GradleRunner.create().apply {
withGradleVersion(TestProperties.gradleVersionForTests)
withProjectDir(workingDir)
withProjectDir(testEnvironment.workingDir)
withArguments(args.toList() + additionalArgs)
forwardOutput()
}
@ -49,6 +55,6 @@ data class TestProject(
gradle(*args).withDebug(true)
fun file(path: String): File =
workingDir.resolve(path)
testEnvironment.workingDir.resolve(path)
}

1
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProjects.kt

@ -8,4 +8,5 @@ object TestProjects {
const val javaLogger = "application/javaLogger"
const val macOptions = "application/macOptions"
const val optionsWithSpaces = "application/optionsWithSpaces"
const val jsMpp = "misc/jsMpp"
}

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

@ -1,9 +1,6 @@
package org.jetbrains.compose.test
object TestProperties {
// __KOTLIN_COMPOSE_VERSION__
val kotlinVersion: String = "1.4.31"
val composeVersion: String
get() = System.getProperty("compose.plugin.version")!!

33
gradle-plugins/compose/src/test/test-projects/misc/jsMpp/build.gradle

@ -0,0 +1,33 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.compose"
}
repositories {
google()
mavenCentral()
jcenter()
maven { url "https://maven.pkg.jetbrains.space/public/p/compose/dev" }
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
}
kotlin {
js(IR) {
browser()
}
jvm {}
sourceSets {
named("commonMain") {
}
named("jsMain") {
}
named("jvmMain") {
dependencies {
implementation(compose.desktop.currentOs)
}
}
}
}

12
gradle-plugins/compose/src/test/test-projects/misc/jsMpp/settings.gradle

@ -0,0 +1,12 @@
pluginManagement {
plugins {
id 'org.jetbrains.kotlin.multiplatform' version 'KOTLIN_VERSION_PLACEHOLDER'
id 'org.jetbrains.compose' version 'COMPOSE_VERSION_PLACEHOLDER'
}
repositories {
mavenLocal()
gradlePluginPortal()
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
}
}
rootProject.name = "jsMpp"

1
gradle-plugins/compose/src/test/test-projects/misc/jsMpp/src/commonMain/kotlin/platform.kt

@ -0,0 +1 @@
expect fun getPlatformName(): String

1
gradle-plugins/compose/src/test/test-projects/misc/jsMpp/src/jsMain/kotlin/platform.kt

@ -0,0 +1 @@
actual fun getPlatformName(): String = "js"

1
gradle-plugins/compose/src/test/test-projects/misc/jsMpp/src/jvmMain/kotlin/platform.kt

@ -0,0 +1 @@
actual fun getPlatformName(): String = "jvm"
Loading…
Cancel
Save