From eeb2f7d3d11182e83bad47231553757e539eb969 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Wed, 6 May 2020 12:28:30 +0300 Subject: [PATCH] Build: Migrate plugin markers to maven-publish publication --- build.gradle.kts | 5 -- buildSrc/build.gradle.kts | 1 + buildSrc/src/main/kotlin/pluginMarkers.kt | 65 +++++++++++++++++++ libraries/commonConfiguration.gradle | 4 ++ .../tools/gradle-tools/pluginMarkers.gradle | 56 ---------------- libraries/tools/kotlin-allopen/build.gradle | 2 + .../kotlin-allopen/plugin-marker/build.gradle | 3 - .../kotlin-gradle-plugin/build.gradle.kts | 2 + .../plugin-marker/build.gradle | 3 - libraries/tools/kotlin-noarg/build.gradle | 2 + .../kotlin-noarg/plugin-marker/build.gradle | 3 - .../tools/kotlin-serialization/build.gradle | 4 +- .../plugin-marker/build.gradle | 3 - settings.gradle | 15 +---- 14 files changed, 80 insertions(+), 88 deletions(-) create mode 100644 buildSrc/src/main/kotlin/pluginMarkers.kt delete mode 100644 libraries/tools/gradle-tools/pluginMarkers.gradle delete mode 100644 libraries/tools/kotlin-allopen/plugin-marker/build.gradle delete mode 100644 libraries/tools/kotlin-gradle-plugin/plugin-marker/build.gradle delete mode 100644 libraries/tools/kotlin-noarg/plugin-marker/build.gradle delete mode 100644 libraries/tools/kotlin-serialization/plugin-marker/build.gradle diff --git a/build.gradle.kts b/build.gradle.kts index 9b152bcb710..bead099c853 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,7 +28,6 @@ buildscript { bootstrapCompilerClasspath(kotlin("compiler-embeddable", bootstrapKotlinVersion)) classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.17") - classpath("com.gradle.publish:plugin-publish-plugin:0.11.0") classpath(kotlin("gradle-plugin", bootstrapKotlinVersion)) classpath("org.jetbrains.dokka:dokka-gradle-plugin:0.9.17") } @@ -325,14 +324,10 @@ val coreLibProjects = listOfNotNull( val gradlePluginProjects = listOf( ":kotlin-gradle-plugin", - ":kotlin-gradle-plugin:plugin-marker", ":kotlin-gradle-plugin-api", -// ":kotlin-gradle-plugin-integration-tests", // TODO: build fails ":kotlin-allopen", - ":kotlin-allopen:plugin-marker", ":kotlin-annotation-processing-gradle", ":kotlin-noarg", - ":kotlin-noarg:plugin-marker", ":kotlin-sam-with-receiver" ) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3ac41f7b00b..ae553aa3c9a 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -97,6 +97,7 @@ repositories { dependencies { implementation(kotlin("stdlib", embeddedKotlinVersion)) implementation("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.17") + implementation("com.gradle.publish:plugin-publish-plugin:0.11.0") implementation("net.rubygrapefruit:native-platform:${property("versions.native-platform")}") implementation("net.rubygrapefruit:native-platform-windows-amd64:${property("versions.native-platform")}") diff --git a/buildSrc/src/main/kotlin/pluginMarkers.kt b/buildSrc/src/main/kotlin/pluginMarkers.kt new file mode 100644 index 00000000000..52535f3578e --- /dev/null +++ b/buildSrc/src/main/kotlin/pluginMarkers.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import com.gradle.publish.PluginBundleExtension +import com.gradle.publish.PluginConfig +import org.gradle.api.Project +import org.gradle.api.publish.PublicationContainer +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.* +import plugins.KotlinBuildPublishingPlugin + +internal const val PLUGIN_MARKER_SUFFIX = ".gradle.plugin" + +fun Project.publishPluginMarkers(withEmptyJars: Boolean = true) { + val pluginDevelopment = extensions.getByType() + val publishingExtension = extensions.getByType() + val mainPublication = publishingExtension.publications[KotlinBuildPublishingPlugin.PUBLICATION_NAME] as MavenPublication + + pluginDevelopment.plugins.forEach { declaration -> + val markerPublication = createMavenMarkerPublication(declaration, mainPublication, publishingExtension.publications) + if (withEmptyJars) { + addEmptyJarArtifacts(markerPublication) + } + } +} + +fun Project.addEmptyJarArtifacts(publication: MavenPublication) { + val emptyJar = getOrCreateTask("emptyJar") { } + publication.artifact(emptyJar.get()) { } + publication.artifact(emptyJar.get()) { classifier = "sources" } + publication.artifact(emptyJar.get()) { classifier = "javadoc" } +} + +// Based on code from `java-gradle-plugin` +// https://github.com/gradle/gradle/blob/v6.4.0/subprojects/plugin-development/src/main/java/org/gradle/plugin/devel/plugins/MavenPluginPublishPlugin.java#L84 +private fun createMavenMarkerPublication( + declaration: PluginConfig, + coordinates: MavenPublication, + publications: PublicationContainer +): MavenPublication { + return publications.create(declaration.name.toString() + "PluginMarkerMaven") { + val pluginId: String = declaration.id + artifactId = pluginId + PLUGIN_MARKER_SUFFIX + groupId = pluginId + pom.withXml { + val root = asElement() + val document = root.ownerDocument + val dependencies = root.appendChild(document.createElement("dependencies")) + val dependency = dependencies.appendChild(document.createElement("dependency")) + val groupId = dependency.appendChild(document.createElement("groupId")) + groupId.textContent = coordinates.groupId + val artifactId = dependency.appendChild(document.createElement("artifactId")) + artifactId.textContent = coordinates.artifactId + val version = dependency.appendChild(document.createElement("version")) + version.textContent = coordinates.version + } + + pom.name.set(declaration.displayName) + pom.description.set(declaration.description) + } +} diff --git a/libraries/commonConfiguration.gradle b/libraries/commonConfiguration.gradle index 72f0ef6a7c6..6598d6d23b6 100644 --- a/libraries/commonConfiguration.gradle +++ b/libraries/commonConfiguration.gradle @@ -122,6 +122,10 @@ ext.configurePublishing = { Project project, configure = { } -> } } +ext.configurePluginMarkers = { Project project, withEmptyJars = true -> + PluginMarkersKt.publishPluginMarkers(project, withEmptyJars) +} + ext.configureLegacyPublishing = { Project project -> project.configure(project) { apply plugin: 'maven' diff --git a/libraries/tools/gradle-tools/pluginMarkers.gradle b/libraries/tools/gradle-tools/pluginMarkers.gradle deleted file mode 100644 index 2c341419cd3..00000000000 --- a/libraries/tools/gradle-tools/pluginMarkers.gradle +++ /dev/null @@ -1,56 +0,0 @@ -ext.pluginMarkerProject = { String pluginProjectId -> - evaluationDependsOn(":$pluginProjectId") - - if (rootProject.ext.get("isSonatypePublish")) { - def warning = "Plugin marker is not created for $pluginProjectId Sonatype publishing" - task('uploadArchives').doLast { println warning } - return - } - - def pluginProject = findProject(":$pluginProjectId") - - repositories.addAll(pluginProject.repositories.toList()) - - apply plugin: 'java' - - dependencies { - compile project(path: pluginProject.path, configuration: 'runtimeJar') - } - - // Remove the default JAR artifact added by the Java plugin - configurations.archives.artifacts.clear() - - // TODO: Migrate to maven-publish publishing - configureLegacyPublishing(project) - - task emptyJar(type: Jar) - - version = project.version + (findProperty('marker_version_suffix') ?: "") - - for (pluginId in pluginProject.pluginBundle.plugins.collect { it.id }) { - def artifactName = "${pluginId}.gradle.plugin" - - artifacts { - ['', 'javadoc', 'sources'].forEach { theClassifier -> - archives(emptyJar) { - group = pluginId - name = artifactName - classifier = theClassifier - } - } - } - - // Publish each gradle plugin marker under its own Maven coordinates pluginId:pluginId.gradle.plugin - def setUpSeparateArtifact = { - addFilter(pluginId) { artifact, file -> artifact.name == artifactName } - def pom = pom(pluginId) - pom.groupId = pluginId - pom.artifactId = "${pluginId}.gradle.plugin" - } - - configure(uploadArchives.repositories.mavenDeployer, setUpSeparateArtifact) - configure(install.repositories.mavenInstaller, setUpSeparateArtifact) - } - - publish.dependsOn uploadArchives -} \ No newline at end of file diff --git a/libraries/tools/kotlin-allopen/build.gradle b/libraries/tools/kotlin-allopen/build.gradle index 27a0660d2c6..67ee59791f4 100644 --- a/libraries/tools/kotlin-allopen/build.gradle +++ b/libraries/tools/kotlin-allopen/build.gradle @@ -50,4 +50,6 @@ pluginBundle { } } +configurePluginMarkers(project) + test.executable = "${JDK_18}/bin/java" \ No newline at end of file diff --git a/libraries/tools/kotlin-allopen/plugin-marker/build.gradle b/libraries/tools/kotlin-allopen/plugin-marker/build.gradle deleted file mode 100644 index 55ed654d5ca..00000000000 --- a/libraries/tools/kotlin-allopen/plugin-marker/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -apply from: "$rootDir/libraries/tools/gradle-tools/pluginMarkers.gradle" - -pluginMarkerProject('kotlin-allopen') diff --git a/libraries/tools/kotlin-gradle-plugin/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin/build.gradle.kts index 4e3f0815ddd..5bdd522d000 100644 --- a/libraries/tools/kotlin-gradle-plugin/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin/build.gradle.kts @@ -206,3 +206,5 @@ pluginBundle { display = "Kotlin Native plugin for CocoaPods integration" ) } + +publishPluginMarkers() diff --git a/libraries/tools/kotlin-gradle-plugin/plugin-marker/build.gradle b/libraries/tools/kotlin-gradle-plugin/plugin-marker/build.gradle deleted file mode 100644 index 93c7d15d469..00000000000 --- a/libraries/tools/kotlin-gradle-plugin/plugin-marker/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -apply from: "$rootDir/libraries/tools/gradle-tools/pluginMarkers.gradle" - -pluginMarkerProject('kotlin-gradle-plugin') diff --git a/libraries/tools/kotlin-noarg/build.gradle b/libraries/tools/kotlin-noarg/build.gradle index dac5ac4baed..5e89e2bbb0c 100644 --- a/libraries/tools/kotlin-noarg/build.gradle +++ b/libraries/tools/kotlin-noarg/build.gradle @@ -56,4 +56,6 @@ pluginBundle { } } +configurePluginMarkers(project) + test.executable = "${JDK_18}/bin/java" \ No newline at end of file diff --git a/libraries/tools/kotlin-noarg/plugin-marker/build.gradle b/libraries/tools/kotlin-noarg/plugin-marker/build.gradle deleted file mode 100644 index fa51a03ea33..00000000000 --- a/libraries/tools/kotlin-noarg/plugin-marker/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -apply from: "$rootDir/libraries/tools/gradle-tools/pluginMarkers.gradle" - -pluginMarkerProject('kotlin-noarg') diff --git a/libraries/tools/kotlin-serialization/build.gradle b/libraries/tools/kotlin-serialization/build.gradle index 462db1a83f0..fbfbe5900b9 100644 --- a/libraries/tools/kotlin-serialization/build.gradle +++ b/libraries/tools/kotlin-serialization/build.gradle @@ -38,4 +38,6 @@ pluginBundle { description = displayName = 'Kotlin compiler plugin for kotlinx.serialization library' } } -} \ No newline at end of file +} + +configurePluginMarkers(project) diff --git a/libraries/tools/kotlin-serialization/plugin-marker/build.gradle b/libraries/tools/kotlin-serialization/plugin-marker/build.gradle deleted file mode 100644 index 4b9ba47be01..00000000000 --- a/libraries/tools/kotlin-serialization/plugin-marker/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -apply from: "$rootDir/libraries/tools/gradle-tools/pluginMarkers.gradle" - -pluginMarkerProject('kotlin-serialization') diff --git a/settings.gradle b/settings.gradle index 16331d6b1e4..bdb53aa41e6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -299,18 +299,11 @@ include ":benchmarks", ":include:kotlin-compiler", ":plugins:jvm-abi-gen", ":plugins:jvm-abi-gen-embeddable", - - // plugin markers: - ':kotlin-gradle-plugin:plugin-marker', - ':kotlin-allopen:plugin-marker', - ':kotlin-noarg:plugin-marker', ":test-instrumenter", - ":kotlinx-serialization-compiler-plugin", ":kotlinx-serialization-ide-plugin", ":kotlin-serialization", - ":kotlin-serialization-unshaded", - ":kotlin-serialization:plugin-marker" + ":kotlin-serialization-unshaded" include ":idea:idea-frontend-fir:idea-fir-low-level-api" @@ -535,16 +528,10 @@ project(":dukat").projectDir = "$rootDir/libraries/tools/dukat" as File project(':js:js.tests').projectDir = "$rootDir/js/js.tests" as File project(':js:js.engines').projectDir = "$rootDir/js/js.engines" as File -// plugin markers: -project(':kotlin-gradle-plugin:plugin-marker').projectDir = file("$rootDir/libraries/tools/kotlin-gradle-plugin/plugin-marker") -project(':kotlin-allopen:plugin-marker').projectDir = file("$rootDir/libraries/tools/kotlin-allopen/plugin-marker") -project(':kotlin-noarg:plugin-marker').projectDir = file("$rootDir/libraries/tools/kotlin-noarg/plugin-marker") - project(':kotlinx-serialization-compiler-plugin').projectDir = file("$rootDir/plugins/kotlin-serialization/kotlin-serialization-compiler") project(':kotlinx-serialization-ide-plugin').projectDir = file("$rootDir/plugins/kotlin-serialization/kotlin-serialization-ide") project(':kotlin-serialization').projectDir = file("$rootDir/libraries/tools/kotlin-serialization") project(':kotlin-serialization-unshaded').projectDir = file("$rootDir/libraries/tools/kotlin-serialization-unshaded") -project(':kotlin-serialization:plugin-marker').projectDir = file("$rootDir/libraries/tools/kotlin-serialization/plugin-marker") // Uncomment to use locally built protobuf-relocated // includeBuild("dependencies/protobuf")