-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gradle, Compose] Allow to specify for which Kotlin platforms compose…
… plugin should be applied According to JB Compose team, it is a useful feature requested by their users and a new plugin should also support it. For example: JetBrains/compose-multiplatform#3695 ^KT-67253 Verification Pending
- Loading branch information
1 parent
2cbdf68
commit 6d12bb7
Showing
6 changed files
with
195 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
.../kotlin/org/jetbrains/kotlin/compose/compiler/gradle/EnabledPlatformsConfigurationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.compose.compiler.gradle | ||
|
||
import org.gradle.kotlin.dsl.getByType | ||
import org.jetbrains.kotlin.compose.compiler.gradle.testUtils.buildProjectWithMPP | ||
import org.jetbrains.kotlin.compose.compiler.gradle.testUtils.composeOptions | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType | ||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl | ||
import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile | ||
import org.jetbrains.kotlin.gradle.utils.named | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertTrue | ||
|
||
class EnabledPlatformsConfigurationTest { | ||
|
||
@OptIn(ExperimentalWasmDsl::class) | ||
@Test | ||
fun allKotlinPlatformsAreUsedByDefault() { | ||
val project = buildProjectWithMPP { | ||
extensions.getByType<KotlinMultiplatformExtension>().apply { | ||
jvm() | ||
js { nodejs() } | ||
wasmJs() | ||
wasmWasi() | ||
linuxX64() | ||
|
||
applyDefaultHierarchyTemplate() | ||
} | ||
} | ||
|
||
project.evaluate() | ||
|
||
listOf( | ||
"compileKotlinMetadata", | ||
"compileCommonMainKotlinMetadata", | ||
"compileKotlinJs", | ||
"compileKotlinJvm", | ||
"compileKotlinWasmJs", | ||
"compileKotlinWasmWasi" | ||
).forEach { | ||
assertTrue( | ||
project.tasks.named<BaseKotlinCompile>(it).get().composeOptions().isNotEmpty(), | ||
"'$it' task does not contain compose plugin options" | ||
) | ||
} | ||
|
||
assertTrue( | ||
project.tasks.named<KotlinNativeCompile>("compileKotlinLinuxX64").get().composeOptions().isNotEmpty(), | ||
"'compileKotlinLinuxX64' task does not contain compose plugin options" | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalWasmDsl::class) | ||
@Test | ||
fun disableKotlinPlatforms() { | ||
val project = buildProjectWithMPP { | ||
extensions.getByType<KotlinMultiplatformExtension>().apply { | ||
jvm() | ||
js { nodejs() } | ||
wasmJs() | ||
wasmWasi() | ||
linuxX64() | ||
|
||
applyDefaultHierarchyTemplate() | ||
} | ||
|
||
extensions.getByType<ComposeCompilerGradlePluginExtension>() | ||
.targetKotlinPlatforms | ||
.set(setOf(KotlinPlatformType.jvm)) | ||
} | ||
|
||
project.evaluate() | ||
|
||
assertTrue( | ||
project.tasks.named<BaseKotlinCompile>("compileKotlinJvm").get().composeOptions().isNotEmpty(), | ||
"'compileKotlinJvm' task does not contain compose plugin options" | ||
) | ||
|
||
listOf( | ||
"compileKotlinMetadata", | ||
"compileCommonMainKotlinMetadata", | ||
"compileKotlinJs", | ||
"compileKotlinWasmJs", | ||
"compileKotlinWasmWasi" | ||
).forEach { | ||
assertTrue( | ||
project.tasks.named<BaseKotlinCompile>(it).get().composeOptions().isEmpty(), | ||
"'$it' task contains compose plugin options" | ||
) | ||
} | ||
|
||
assertTrue( | ||
project.tasks.named<KotlinNativeCompile>("compileKotlinLinuxX64").get().composeOptions().isEmpty(), | ||
"'compileKotlinLinuxX64' task contains compose plugin options" | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ionalTest/kotlin/org/jetbrains/kotlin/compose/compiler/gradle/testUtils/composeOptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.compose.compiler.gradle.testUtils | ||
|
||
import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile | ||
|
||
fun BaseKotlinCompile.composeOptions() = pluginOptions.get() | ||
.flatMap { compilerPluginConfig -> | ||
compilerPluginConfig.allOptions().filter { it.key == "androidx.compose.compiler.plugins.kotlin" }.values | ||
} | ||
.flatten() | ||
.map { it.key to it.value } | ||
|
||
fun KotlinNativeCompile.composeOptions() = compilerPluginOptions | ||
.allOptions() | ||
.filter { it.key == "androidx.compose.compiler.plugins.kotlin" }.values | ||
.flatten() | ||
.map { it.key to it.value } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters