From 078849d133703959e9ca14aba50ad023f024bd4b Mon Sep 17 00:00:00 2001 From: Alexander Likhachev Date: Tue, 16 Feb 2021 18:57:09 +0300 Subject: [PATCH] [Build] Fix configuration cache issues with install task * `install` task provided by `maven` plugin doesn't support configuration cache so replace `maven` plugin with `maven-publish` and use task that is subtype of PublishToMavenRepository. `maven-publish` partially support configuration cache, see https://github.com/gradle/gradle/issues/13468 * Apply `signing` plugin only if it really needed. The plugin doesn't support configuration cache. See https://github.com/gradle/gradle/issues/13470 Relates to #KT-44611 --- .../plugins/KotlinBuildPublishingPlugin.kt | 23 ++++++++----------- .../build.gradle.kts | 20 ++++++++++++++-- .../build.gradle | 19 +++++++++++++-- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/buildSrc/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt b/buildSrc/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt index 022e49d7f12..6f8dd28ce2d 100644 --- a/buildSrc/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt +++ b/buildSrc/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt @@ -16,7 +16,6 @@ import org.gradle.api.publish.maven.plugins.MavenPublishPlugin import org.gradle.api.publish.maven.tasks.PublishToMavenRepository import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.* -import org.gradle.plugins.signing.Sign import org.gradle.plugins.signing.SigningExtension import org.gradle.plugins.signing.SigningPlugin import java.util.* @@ -27,7 +26,6 @@ class KotlinBuildPublishingPlugin @Inject constructor( ) : Plugin { override fun apply(target: Project): Unit = with(target) { apply() - apply() val publishedRuntime = configurations.maybeCreate(RUNTIME_CONFIGURATION).apply { isCanBeConsumed = false @@ -129,13 +127,20 @@ fun Project.configureDefaultPublishing() { name = KotlinBuildPublishingPlugin.REPOSITORY_NAME url = file("${project.rootDir}/build/repo").toURI() } + mavenLocal() // to workaround configuration cache issues with 'publishToMavenLocal' task } } - configureSigning() + val signingRequired = project.providers.gradleProperty("signingRequired").forUseAtConfigurationTime().orNull?.toBoolean() + ?: project.providers.gradleProperty("isSonatypeRelease").forUseAtConfigurationTime().orNull?.toBoolean() ?: false + + if (signingRequired) { + apply() + configureSigning() + } tasks.register("install") { - dependsOn(tasks.named("publishToMavenLocal")) + dependsOn(tasks.named("publishAllPublicationsToMavenLocalRepository")) } tasks.withType() @@ -144,20 +149,10 @@ fun Project.configureDefaultPublishing() { } private fun Project.configureSigning() { - val signingRequired = provider { - project.findProperty("signingRequired")?.toString()?.toBoolean() - ?: project.property("isSonatypeRelease") as Boolean - } - configure { - setRequired(signingRequired) sign(extensions.getByType().publications) // all publications useGpgCmd() } - - tasks.withType().configureEach { - setOnlyIf { signingRequired.get() } - } } fun TaskProvider.configureRepository() = diff --git a/libraries/examples/annotation-processor-example/build.gradle.kts b/libraries/examples/annotation-processor-example/build.gradle.kts index b9b1b951af3..f0add7e434e 100644 --- a/libraries/examples/annotation-processor-example/build.gradle.kts +++ b/libraries/examples/annotation-processor-example/build.gradle.kts @@ -1,10 +1,11 @@ import org.jetbrains.kotlin.pill.PillExtension +import plugins.configureKotlinPomAttributes description = "Simple Annotation Processor for testing kapt" plugins { kotlin("jvm") - maven // only used for installing to mavenLocal() + `maven-publish` // only used for installing to mavenLocal() id("jps-compatible") } @@ -13,9 +14,24 @@ pill { } dependencies { - compile(kotlinStdlib()) + implementation(kotlinStdlib()) } sourceSets { "test" {} +} + +publishing { + publications { + create("main") { + from(components["java"]) + } + } + repositories { + mavenLocal() // to workaround configuration cache issues with 'publishToMavenLocal' task + } +} + +tasks.register("install") { + dependsOn(tasks.named("publishAllPublicationsToMavenLocalRepository")) } \ No newline at end of file diff --git a/libraries/examples/kotlin-gradle-subplugin-example/build.gradle b/libraries/examples/kotlin-gradle-subplugin-example/build.gradle index ccd251c6257..9c6dff29219 100644 --- a/libraries/examples/kotlin-gradle-subplugin-example/build.gradle +++ b/libraries/examples/kotlin-gradle-subplugin-example/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'kotlin' -apply plugin: 'maven' +apply plugin: 'maven-publish' apply plugin: 'jps-compatible' repositories { @@ -38,4 +38,19 @@ dependencies { // Relocate `com.intellij.*` and some other classes to match those in the `kotlin-compiler-embeddable` // (for example, the actual package at runtime is `org.jetbrains.kotlin.com.intellij.*`): ArtifactsKt.runtimeJar(project, EmbeddableKt.rewriteDefaultJarDepsToShadedCompiler(project, {}), {}) -// In a standalone build, you can setup the relocation with the Shadow plugin. \ No newline at end of file +// In a standalone build, you can setup the relocation with the Shadow plugin. + +publishing { + publications { + main(MavenPublication) { + artifact tasks.named("embeddable") + } + } + repositories { + mavenLocal() // to workaround configuration cache issues with 'publishToMavenLocal' task + } +} + +tasks.register("install") { + dependsOn(tasks.named("publishAllPublicationsToMavenLocalRepository")) +} \ No newline at end of file