From b6edf9a86eaf00096b41dd1a69fb78e1af9b03b5 Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Wed, 8 Jun 2022 11:38:33 +0200 Subject: [PATCH] Shadow Gradle plugin 3rd party dependencies Such dependencies will be embedded into plugin jar and their package will be relocated. This is need to avoid dependency conflicts with user build scripts dependencies or other Gradle plugins. Kotlin project dependencies are not shadowed. ^KT-46034 Fixed --- gradle/verification-metadata.xml | 18 ++++++++++ .../kotlin-gradle-plugin/build.gradle.kts | 34 +++++++++++++++---- .../kotlin-tooling-metadata/build.gradle.kts | 1 + .../atomicfu-compiler/build.gradle.kts | 1 - settings.gradle | 4 +++ wasm/wasm.ir/build.gradle.kts | 1 + 6 files changed, 51 insertions(+), 8 deletions(-) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 663a888f577..6d2a443ae39 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -1846,6 +1846,12 @@ + + + + + + @@ -3023,6 +3029,12 @@ + + + + + + @@ -5806,6 +5818,12 @@ + + + + + + diff --git a/libraries/tools/kotlin-gradle-plugin/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin/build.gradle.kts index ae0d3ba10f8..3f29e9e4b21 100644 --- a/libraries/tools/kotlin-gradle-plugin/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin/build.gradle.kts @@ -1,5 +1,7 @@ import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.pill.PillExtension +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import com.github.jengelman.gradle.plugins.shadow.transformers.DontIncludeResourceTransformer plugins { id("gradle-plugin-common-configuration") @@ -54,18 +56,18 @@ dependencies { commonCompileOnly(intellijCore()) commonCompileOnly(commonDependency("org.jetbrains.teamcity:serviceMessages")) commonCompileOnly("com.gradle:gradle-enterprise-gradle-plugin:3.9") + commonCompileOnly(commonDependency("com.google.code.gson:gson")) + commonCompileOnly(commonDependency("com.google.guava:guava")) + commonCompileOnly("de.undercouch:gradle-download-task:4.1.1") + commonCompileOnly("com.github.gundy:semver4j:0.16.4:nodeps") { + exclude(group = "*") + } + commonCompileOnly(project(":kotlin-tooling-metadata")) commonImplementation(project(":kotlin-gradle-plugin-idea")) commonImplementation(project(":kotlin-util-klib")) commonImplementation(project(":native:kotlin-klib-commonizer-api")) - commonImplementation(project(":kotlin-tooling-metadata")) commonImplementation(project(":kotlin-project-model")) - commonImplementation(commonDependency("com.google.code.gson:gson")) - commonImplementation(commonDependency("com.google.guava:guava")) - commonImplementation("de.undercouch:gradle-download-task:4.1.1") - commonImplementation("com.github.gundy:semver4j:0.16.4:nodeps") { - exclude(group = "*") - } commonRuntimeOnly(project(":kotlin-compiler-embeddable")) commonRuntimeOnly(project(":kotlin-annotation-processing-gradle")) @@ -80,6 +82,11 @@ dependencies { embedded(commonDependency("com.google.code.gson:gson")) { isTransitive = false } embedded(commonDependency("com.google.guava:guava")) { isTransitive = false } embedded(commonDependency("org.jetbrains.teamcity:serviceMessages")) { isTransitive = false } + embedded(project(":kotlin-tooling-metadata")) { isTransitive = false } + embedded("de.undercouch:gradle-download-task:4.1.1") + embedded("com.github.gundy:semver4j:0.16.4:nodeps") { + exclude(group = "*") + } if (!kotlinBuildProperties.isInJpsBuildIdeaSync) { "functionalTestImplementation"("com.android.tools.build:gradle:4.0.1") { @@ -87,6 +94,7 @@ dependencies { } "functionalTestImplementation"(gradleKotlinDsl()) "functionalTestImplementation"(project(":kotlin-gradle-plugin-kpm-android")) + "functionalTestImplementation"(project(":kotlin-tooling-metadata")) "functionalTestImplementation"(testFixtures(project(":kotlin-gradle-plugin-idea"))) } @@ -102,6 +110,7 @@ dependencies { testImplementation(project(":kotlin-test:kotlin-test-junit")) testImplementation(commonDependency("junit:junit")) testImplementation(project(":kotlin-gradle-statistics")) + testImplementation(project(":kotlin-tooling-metadata")) } if (kotlinBuildProperties.isInJpsBuildIdeaSync) { @@ -135,6 +144,17 @@ tasks { register("dokka") { dependsOn(named("dokkaJavadoc")) } + + withType().configureEach { + relocate("com.github.gundy", "$kotlinEmbeddableRootPackage.com.github.gundy") + relocate("de.undercouch.gradle.tasks.download", "$kotlinEmbeddableRootPackage.de.undercouch.gradle.tasks.download") + + // don't expose external Gradle plugin marker + // workaround from https://github.com/johnrengelman/shadow/issues/505#issuecomment-644098082 + transform(DontIncludeResourceTransformer::class.java) { + resource = "META-INF/gradle-plugins/de.undercouch.download.properties" + } + } } projectTest { diff --git a/libraries/tools/kotlin-tooling-metadata/build.gradle.kts b/libraries/tools/kotlin-tooling-metadata/build.gradle.kts index ebd49a5439e..e0c6285f12b 100644 --- a/libraries/tools/kotlin-tooling-metadata/build.gradle.kts +++ b/libraries/tools/kotlin-tooling-metadata/build.gradle.kts @@ -7,6 +7,7 @@ plugins { publish() sourcesJar() javadocJar() +configureKotlinCompileTasksGradleCompatibility() dependencies { implementation(kotlinStdlib()) diff --git a/plugins/atomicfu/atomicfu-compiler/build.gradle.kts b/plugins/atomicfu/atomicfu-compiler/build.gradle.kts index f88bd960031..6744c529fff 100644 --- a/plugins/atomicfu/atomicfu-compiler/build.gradle.kts +++ b/plugins/atomicfu/atomicfu-compiler/build.gradle.kts @@ -7,7 +7,6 @@ description = "Atomicfu Compiler Plugin" plugins { kotlin("jvm") id("jps-compatible") - id("de.undercouch.download") } val antLauncherJar by configurations.creating diff --git a/settings.gradle b/settings.gradle index ba2701409aa..ec0f07e7499 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,6 +16,10 @@ pluginManagement { maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" } } } + + plugins { + id "de.undercouch.download" version "5.1.0" + } } buildscript { diff --git a/wasm/wasm.ir/build.gradle.kts b/wasm/wasm.ir/build.gradle.kts index 9519ab340bb..aaf870d2c59 100644 --- a/wasm/wasm.ir/build.gradle.kts +++ b/wasm/wasm.ir/build.gradle.kts @@ -2,6 +2,7 @@ plugins { kotlin("jvm") id("jps-compatible") kotlin("plugin.serialization") + id("de.undercouch.download") } dependencies {