From 9b40de61a1a4b71cd998c586b75eed950294550d Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Mon, 25 Oct 2021 11:33:43 +0300 Subject: [PATCH] Provide DSL extension for configuring JB Compose repo (#1301) --- .../org/jetbrains/compose/ComposePlugin.kt | 30 ++++++++++++++----- .../application/jvm/build.gradle | 4 +-- .../application/jvmKotlinDsl/build.gradle.kts | 4 +-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt index 8e6f0caab6..c17e1c88dc 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt +++ b/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 { 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 { } } +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(project.repositories) { + fun doCall(): MavenArtifactRepository = + project.repositories.jetbrainsCompose() + }) + } +} diff --git a/gradle-plugins/compose/src/test/test-projects/application/jvm/build.gradle b/gradle-plugins/compose/src/test/test-projects/application/jvm/build.gradle index 04db9e8c2a..75c1067643 100644 --- a/gradle-plugins/compose/src/test/test-projects/application/jvm/build.gradle +++ b/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 { diff --git a/gradle-plugins/compose/src/test/test-projects/application/jvmKotlinDsl/build.gradle.kts b/gradle-plugins/compose/src/test/test-projects/application/jvmKotlinDsl/build.gradle.kts index 0186e15b18..442f6d36cf 100644 --- a/gradle-plugins/compose/src/test/test-projects/application/jvmKotlinDsl/build.gradle.kts +++ b/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 {