Browse Source

Add compose Gradle extension to dependency blocks

Before this change, the following Groovy DSL code would not work:
```
dependency {
  implementation compose.desktop.currentOS
}

// or

kotlin {
    jvm { withJava() }
    sourceSets {
        named("jvmMain") {
            dependencies {
                implementation(compose.desktop.currentOs)
            }
        }
    }
}
```
pull/102/head
Alexey Tsvetkov 4 years ago committed by Alexey Tsvetkov
parent
commit
bef34ad7d2
  1. 11
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt

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

@ -5,6 +5,7 @@ package org.jetbrains.compose
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.compose.desktop.DesktopExtension
import org.jetbrains.compose.desktop.application.internal.configureApplicationImpl
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
@ -17,6 +18,16 @@ class ComposePlugin : Plugin<Project> {
val composeExtension = project.extensions.create("compose", ComposeExtension::class.java)
val desktopExtension = composeExtension.extensions.create("desktop", DesktopExtension::class.java)
if (!project.buildFile.endsWith(".gradle.kts")) {
// add compose extension for Groovy DSL to work
project.dependencies.extensions.add("compose", Dependencies)
project.plugins.withId("org.jetbrains.kotlin.multiplatform") {
(project.extensions.getByName("kotlin") as? ExtensionAware)?.apply {
extensions.add("compose", Dependencies)
}
}
}
project.afterEvaluate {
if (desktopExtension._isApplicationInitialized) {
// If application object was not accessed in a script,

Loading…
Cancel
Save