Build: Migrate plugin markers to maven-publish publication
This commit is contained in:
@@ -28,7 +28,6 @@ buildscript {
|
|||||||
bootstrapCompilerClasspath(kotlin("compiler-embeddable", bootstrapKotlinVersion))
|
bootstrapCompilerClasspath(kotlin("compiler-embeddable", bootstrapKotlinVersion))
|
||||||
|
|
||||||
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.17")
|
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(kotlin("gradle-plugin", bootstrapKotlinVersion))
|
||||||
classpath("org.jetbrains.dokka:dokka-gradle-plugin:0.9.17")
|
classpath("org.jetbrains.dokka:dokka-gradle-plugin:0.9.17")
|
||||||
}
|
}
|
||||||
@@ -325,14 +324,10 @@ val coreLibProjects = listOfNotNull(
|
|||||||
|
|
||||||
val gradlePluginProjects = listOf(
|
val gradlePluginProjects = listOf(
|
||||||
":kotlin-gradle-plugin",
|
":kotlin-gradle-plugin",
|
||||||
":kotlin-gradle-plugin:plugin-marker",
|
|
||||||
":kotlin-gradle-plugin-api",
|
":kotlin-gradle-plugin-api",
|
||||||
// ":kotlin-gradle-plugin-integration-tests", // TODO: build fails
|
|
||||||
":kotlin-allopen",
|
":kotlin-allopen",
|
||||||
":kotlin-allopen:plugin-marker",
|
|
||||||
":kotlin-annotation-processing-gradle",
|
":kotlin-annotation-processing-gradle",
|
||||||
":kotlin-noarg",
|
":kotlin-noarg",
|
||||||
":kotlin-noarg:plugin-marker",
|
|
||||||
":kotlin-sam-with-receiver"
|
":kotlin-sam-with-receiver"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib", embeddedKotlinVersion))
|
implementation(kotlin("stdlib", embeddedKotlinVersion))
|
||||||
implementation("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.17")
|
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:${property("versions.native-platform")}")
|
||||||
implementation("net.rubygrapefruit:native-platform-windows-amd64:${property("versions.native-platform")}")
|
implementation("net.rubygrapefruit:native-platform-windows-amd64:${property("versions.native-platform")}")
|
||||||
|
|||||||
@@ -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<PluginBundleExtension>()
|
||||||
|
val publishingExtension = extensions.getByType<PublishingExtension>()
|
||||||
|
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<Jar>("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<MavenPublication>(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -122,6 +122,10 @@ ext.configurePublishing = { Project project, configure = { } ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ext.configurePluginMarkers = { Project project, withEmptyJars = true ->
|
||||||
|
PluginMarkersKt.publishPluginMarkers(project, withEmptyJars)
|
||||||
|
}
|
||||||
|
|
||||||
ext.configureLegacyPublishing = { Project project ->
|
ext.configureLegacyPublishing = { Project project ->
|
||||||
project.configure(project) {
|
project.configure(project) {
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -50,4 +50,6 @@ pluginBundle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configurePluginMarkers(project)
|
||||||
|
|
||||||
test.executable = "${JDK_18}/bin/java"
|
test.executable = "${JDK_18}/bin/java"
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
apply from: "$rootDir/libraries/tools/gradle-tools/pluginMarkers.gradle"
|
|
||||||
|
|
||||||
pluginMarkerProject('kotlin-allopen')
|
|
||||||
@@ -206,3 +206,5 @@ pluginBundle {
|
|||||||
display = "Kotlin Native plugin for CocoaPods integration"
|
display = "Kotlin Native plugin for CocoaPods integration"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publishPluginMarkers()
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
apply from: "$rootDir/libraries/tools/gradle-tools/pluginMarkers.gradle"
|
|
||||||
|
|
||||||
pluginMarkerProject('kotlin-gradle-plugin')
|
|
||||||
@@ -56,4 +56,6 @@ pluginBundle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configurePluginMarkers(project)
|
||||||
|
|
||||||
test.executable = "${JDK_18}/bin/java"
|
test.executable = "${JDK_18}/bin/java"
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
apply from: "$rootDir/libraries/tools/gradle-tools/pluginMarkers.gradle"
|
|
||||||
|
|
||||||
pluginMarkerProject('kotlin-noarg')
|
|
||||||
@@ -39,3 +39,5 @@ pluginBundle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configurePluginMarkers(project)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
apply from: "$rootDir/libraries/tools/gradle-tools/pluginMarkers.gradle"
|
|
||||||
|
|
||||||
pluginMarkerProject('kotlin-serialization')
|
|
||||||
+1
-14
@@ -299,18 +299,11 @@ include ":benchmarks",
|
|||||||
":include:kotlin-compiler",
|
":include:kotlin-compiler",
|
||||||
":plugins:jvm-abi-gen",
|
":plugins:jvm-abi-gen",
|
||||||
":plugins:jvm-abi-gen-embeddable",
|
":plugins:jvm-abi-gen-embeddable",
|
||||||
|
|
||||||
// plugin markers:
|
|
||||||
':kotlin-gradle-plugin:plugin-marker',
|
|
||||||
':kotlin-allopen:plugin-marker',
|
|
||||||
':kotlin-noarg:plugin-marker',
|
|
||||||
":test-instrumenter",
|
":test-instrumenter",
|
||||||
|
|
||||||
":kotlinx-serialization-compiler-plugin",
|
":kotlinx-serialization-compiler-plugin",
|
||||||
":kotlinx-serialization-ide-plugin",
|
":kotlinx-serialization-ide-plugin",
|
||||||
":kotlin-serialization",
|
":kotlin-serialization",
|
||||||
":kotlin-serialization-unshaded",
|
":kotlin-serialization-unshaded"
|
||||||
":kotlin-serialization:plugin-marker"
|
|
||||||
|
|
||||||
include ":idea:idea-frontend-fir:idea-fir-low-level-api"
|
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.tests').projectDir = "$rootDir/js/js.tests" as File
|
||||||
project(':js:js.engines').projectDir = "$rootDir/js/js.engines" 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-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(':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').projectDir = file("$rootDir/libraries/tools/kotlin-serialization")
|
||||||
project(':kotlin-serialization-unshaded').projectDir = file("$rootDir/libraries/tools/kotlin-serialization-unshaded")
|
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
|
// Uncomment to use locally built protobuf-relocated
|
||||||
// includeBuild("dependencies/protobuf")
|
// includeBuild("dependencies/protobuf")
|
||||||
|
|||||||
Reference in New Issue
Block a user