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 package org.jetbrains.compose
import groovy.lang.Closure
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.ComponentMetadataContext import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.ComponentMetadataRule import org.gradle.api.artifacts.ComponentMetadataRule
import org.gradle.api.artifacts.dsl.ComponentModuleMetadataHandler import org.gradle.api.artifacts.dsl.ComponentModuleMetadataHandler
import org.gradle.api.artifacts.dsl.DependencyHandler 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.gradle.api.plugins.ExtensionAware
import org.jetbrains.compose.android.AndroidExtension import org.jetbrains.compose.android.AndroidExtension
import org.jetbrains.compose.desktop.DesktopExtension import org.jetbrains.compose.desktop.DesktopExtension
@ -32,13 +35,7 @@ class ComposePlugin : Plugin<Project> {
val androidExtension = composeExtension.extensions.create("android", AndroidExtension::class.java) val androidExtension = composeExtension.extensions.create("android", AndroidExtension::class.java)
if (!project.buildFile.endsWith(".gradle.kts")) { if (!project.buildFile.endsWith(".gradle.kts")) {
// add compose extension for Groovy DSL to work setUpGroovyDslExtensions(project)
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.initializePreview() 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) fun KotlinDependencyHandler.compose(groupWithArtifact: String) = composeDependency(groupWithArtifact)
val KotlinDependencyHandler.compose get() = ComposePlugin.Dependencies val KotlinDependencyHandler.compose get() = ComposePlugin.Dependencies
@ -218,3 +218,19 @@ fun DependencyHandler.compose(groupWithArtifact: String) = composeDependency(gro
val DependencyHandler.compose get() = ComposePlugin.Dependencies val DependencyHandler.compose get() = ComposePlugin.Dependencies
private fun composeDependency(groupWithArtifact: String) = "$groupWithArtifact:$composeVersion" 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 { repositories {
google() google()
mavenCentral() mavenCentral()
maven { jetbrainsCompose()
url "https://maven.pkg.jetbrains.space/public/p/compose/dev"
}
} }
dependencies { 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 import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins { plugins {
@ -9,7 +9,7 @@ plugins {
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") jetbrainsCompose()
} }
dependencies { dependencies {

Loading…
Cancel
Save