Browse Source

Support org.jetbrains.kotlin.js plugin (#1851)

Resolves #1821
pull/1868/head
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
1e71abb3c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt
  2. 4
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/projectExtensions.kt
  3. 44
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/WebExtension.kt

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

@ -137,17 +137,6 @@ class ComposePlugin : Plugin<Project> {
} }
} }
} }
checkAndWarnAboutUsingJsPlugin(project)
}
private fun checkAndWarnAboutUsingJsPlugin(project: Project) {
val msg = "'$COMPOSE_PLUGIN_ID' plugin is not compatible with '$KOTLIN_JS_PLUGIN_ID' plugin. " +
"Use '$KOTLIN_MPP_PLUGIN_ID' instead"
project.plugins.withId(KOTLIN_JS_PLUGIN_ID) {
project.logger.error(msg)
}
} }
class RedirectAndroidVariants : ComponentMetadataRule { class RedirectAndroidVariants : ComponentMetadataRule {

4
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/projectExtensions.kt

@ -12,6 +12,7 @@ import org.gradle.api.tasks.SourceSetContainer
import org.gradle.util.GradleVersion import org.gradle.util.GradleVersion
import org.jetbrains.compose.ComposeExtension import org.jetbrains.compose.ComposeExtension
import org.jetbrains.compose.web.WebExtension import org.jetbrains.compose.web.WebExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
internal val Project.composeExt: ComposeExtension? internal val Project.composeExt: ComposeExtension?
@ -26,6 +27,9 @@ internal val Project.mppExt: KotlinMultiplatformExtension
internal val Project.mppExtOrNull: KotlinMultiplatformExtension? internal val Project.mppExtOrNull: KotlinMultiplatformExtension?
get() = extensions.findByType(KotlinMultiplatformExtension::class.java) get() = extensions.findByType(KotlinMultiplatformExtension::class.java)
internal val Project.kotlinJsExtOrNull: KotlinJsProjectExtension?
get() = extensions.findByType(KotlinJsProjectExtension::class.java)
internal val Project.javaSourceSets: SourceSetContainer internal val Project.javaSourceSets: SourceSetContainer
get() = if (GradleVersion.current() < GradleVersion.version("7.1")) { get() = if (GradleVersion.current() < GradleVersion.version("7.1")) {
convention.getPlugin(JavaPluginConvention::class.java).sourceSets convention.getPlugin(JavaPluginConvention::class.java).sourceSets

44
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/WebExtension.kt

@ -7,8 +7,10 @@ package org.jetbrains.compose.web
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.compose.internal.kotlinJsExtOrNull
import org.jetbrains.compose.internal.mppExt import org.jetbrains.compose.internal.mppExt
import org.jetbrains.compose.internal.mppExtOrNull import org.jetbrains.compose.internal.mppExtOrNull
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
@ -46,16 +48,36 @@ abstract class WebExtension : ExtensionAware {
} }
private fun defaultJsTargetsToConfigure(project: Project): Set<KotlinJsIrTarget> { private fun defaultJsTargetsToConfigure(project: Project): Set<KotlinJsIrTarget> {
val mppTargets = project.mppExtOrNull?.targets?.asMap?.values ?: emptySet() val mppExt = project.mppExtOrNull
val jsIRTargets = mppTargets.filterIsInstanceTo(LinkedHashSet<KotlinJsIrTarget>())
if (mppExt != null) {
return if (jsIRTargets.size > 1) { val mppTargets = mppExt.targets.asMap.values
project.logger.error( val jsIRTargets = mppTargets.filterIsInstanceTo(LinkedHashSet<KotlinJsIrTarget>())
"w: Default configuration for Compose Web is disabled: " +
"multiple Kotlin JS IR targets are defined. " + return if (jsIRTargets.size > 1) {
"Specify Compose Web Kotlin targets by using `compose.web.targets()`" project.logger.error(
) "w: Default configuration for Compose for Web is disabled: " +
emptySet() "multiple Kotlin JS IR targets are defined. " +
} else jsIRTargets "Specify Compose for Web Kotlin targets by using `compose.web.targets()`"
)
emptySet()
} else jsIRTargets
}
val jsExt = project.kotlinJsExtOrNull
if (jsExt != null) {
val target = jsExt.target
return if (target is KotlinJsIrTarget) {
setOf(target)
} else {
project.logger.error(
"w: Default configuration for Compose for Web is disabled: " +
"Compose for Web does not support legacy (non-IR) JS targets"
)
emptySet()
}
}
return emptySet()
} }
} }
Loading…
Cancel
Save