Browse Source

Provide DSL extension for configuring JB Compose repo (#1301)

pull/1312/head
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
9b40de61a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt
  2. 4
      gradle-plugins/compose/src/test/test-projects/application/jvm/build.gradle
  3. 4
      gradle-plugins/compose/src/test/test-projects/application/jvmKotlinDsl/build.gradle.kts

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

@ -7,12 +7,15 @@
package org.jetbrains.compose
import groovy.lang.Closure
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.ComponentMetadataRule
import org.gradle.api.artifacts.dsl.ComponentModuleMetadataHandler
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.compose.android.AndroidExtension
import org.jetbrains.compose.desktop.DesktopExtension
@ -32,13 +35,7 @@ class ComposePlugin : Plugin<Project> {
val androidExtension = composeExtension.extensions.create("android", AndroidExtension::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)
}
}
setUpGroovyDslExtensions(project)
}
project.initializePreview()
@ -211,6 +208,9 @@ class ComposePlugin : Plugin<Project> {
}
}
fun RepositoryHandler.jetbrainsCompose(): MavenArtifactRepository =
maven { repo -> repo.setUrl("https://maven.pkg.jetbrains.space/public/p/compose/dev") }
fun KotlinDependencyHandler.compose(groupWithArtifact: String) = composeDependency(groupWithArtifact)
val KotlinDependencyHandler.compose get() = ComposePlugin.Dependencies
@ -218,3 +218,19 @@ fun DependencyHandler.compose(groupWithArtifact: String) = composeDependency(gro
val DependencyHandler.compose get() = ComposePlugin.Dependencies
private fun composeDependency(groupWithArtifact: String) = "$groupWithArtifact:$composeVersion"
private fun setUpGroovyDslExtensions(project: Project) {
// add compose extension for Groovy DSL to work
project.dependencies.extensions.add("compose", ComposePlugin.Dependencies)
project.plugins.withId("org.jetbrains.kotlin.multiplatform") {
(project.extensions.getByName("kotlin") as? ExtensionAware)?.apply {
extensions.add("compose", ComposePlugin.Dependencies)
}
}
(project.repositories as? ExtensionAware)?.extensions?.apply {
add("jetbrainsCompose", object : Closure<MavenArtifactRepository>(project.repositories) {
fun doCall(): MavenArtifactRepository =
project.repositories.jetbrainsCompose()
})
}
}

4
gradle-plugins/compose/src/test/test-projects/application/jvm/build.gradle

@ -8,9 +8,7 @@ plugins {
repositories {
google()
mavenCentral()
maven {
url "https://maven.pkg.jetbrains.space/public/p/compose/dev"
}
jetbrainsCompose()
}
dependencies {

4
gradle-plugins/compose/src/test/test-projects/application/jvmKotlinDsl/build.gradle.kts

@ -1,4 +1,4 @@
import org.jetbrains.compose.compose
import org.jetbrains.compose.*
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
@ -9,7 +9,7 @@ plugins {
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
jetbrainsCompose()
}
dependencies {

Loading…
Cancel
Save