mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
Apply common configuration to custom publications in kotlin-test
To do that, extract parts of publishing setup into reusable functions. This change makes signing and repository configuration applied to all project publications, not just to the Main one. Also: - Get rid of dependencies from non-default variants in the root pom - Add an empty javadoc jar KT-40225
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
@@ -71,62 +71,11 @@ class KotlinBuildPublishingPlugin @Inject constructor(
|
||||
create<MavenPublication>(PUBLICATION_NAME) {
|
||||
from(kotlinLibraryComponent)
|
||||
|
||||
pom {
|
||||
packaging = "jar"
|
||||
name.set(humanReadableName(project))
|
||||
description.set(project.description ?: humanReadableName(project))
|
||||
url.set("https://kotlinlang.org/")
|
||||
licenses {
|
||||
license {
|
||||
name.set("The Apache License, Version 2.0")
|
||||
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url.set("https://github.com/JetBrains/kotlin")
|
||||
connection.set("scm:git:https://github.com/JetBrains/kotlin.git")
|
||||
developerConnection.set("scm:git:https://github.com/JetBrains/kotlin.git")
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
name.set("Kotlin Team")
|
||||
organization.set("JetBrains")
|
||||
organizationUrl.set("https://www.jetbrains.com")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = REPOSITORY_NAME
|
||||
url = file("${project.rootDir}/build/repo").toURI()
|
||||
configureKotlinPomAttributes(project)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val signingRequired = provider {
|
||||
project.findProperty("signingRequired")?.toString()?.toBoolean()
|
||||
?: project.property("isSonatypeRelease") as Boolean
|
||||
}
|
||||
|
||||
configure<SigningExtension> {
|
||||
setRequired(signingRequired)
|
||||
sign(extensions.getByType<PublishingExtension>().publications[PUBLICATION_NAME])
|
||||
useGpgCmd()
|
||||
}
|
||||
|
||||
tasks.withType<Sign>().configureEach {
|
||||
setOnlyIf { signingRequired.get() }
|
||||
}
|
||||
|
||||
tasks.register("install") {
|
||||
dependsOn(tasks.named("publishToMavenLocal"))
|
||||
}
|
||||
|
||||
tasks.named<PublishToMavenRepository>("publish${PUBLICATION_NAME}PublicationTo${REPOSITORY_NAME}Repository")
|
||||
.configureRepository()
|
||||
configureDefaultPublishing()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -137,13 +86,84 @@ class KotlinBuildPublishingPlugin @Inject constructor(
|
||||
const val COMPILE_CONFIGURATION = "publishedCompile"
|
||||
const val RUNTIME_CONFIGURATION = "publishedRuntime"
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun humanReadableName(project: Project) =
|
||||
project.name.split("-").joinToString(separator = " ") { it.capitalize(Locale.ROOT) }
|
||||
}
|
||||
}
|
||||
|
||||
fun TaskProvider<PublishToMavenRepository>.configureRepository() = configure {
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
private fun humanReadableName(name: String) =
|
||||
name.split("-").joinToString(separator = " ") { it.capitalize(Locale.ROOT) }
|
||||
|
||||
fun MavenPublication.configureKotlinPomAttributes(project: Project, explicitDescription: String? = null) {
|
||||
val publication = this
|
||||
pom {
|
||||
packaging = "jar"
|
||||
name.set(humanReadableName(publication.artifactId))
|
||||
description.set(explicitDescription ?: project.description ?: humanReadableName(publication.artifactId))
|
||||
url.set("https://kotlinlang.org/")
|
||||
licenses {
|
||||
license {
|
||||
name.set("The Apache License, Version 2.0")
|
||||
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url.set("https://github.com/JetBrains/kotlin")
|
||||
connection.set("scm:git:https://github.com/JetBrains/kotlin.git")
|
||||
developerConnection.set("scm:git:https://github.com/JetBrains/kotlin.git")
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
name.set("Kotlin Team")
|
||||
organization.set("JetBrains")
|
||||
organizationUrl.set("https://www.jetbrains.com")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Project.configureDefaultPublishing() {
|
||||
configure<PublishingExtension> {
|
||||
repositories {
|
||||
maven {
|
||||
name = KotlinBuildPublishingPlugin.REPOSITORY_NAME
|
||||
url = file("${project.rootDir}/build/repo").toURI()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configureSigning()
|
||||
|
||||
tasks.register("install") {
|
||||
dependsOn(tasks.named("publishToMavenLocal"))
|
||||
}
|
||||
|
||||
tasks.withType<PublishToMavenRepository>()
|
||||
.matching { it.name.endsWith("PublicationTo${KotlinBuildPublishingPlugin.REPOSITORY_NAME}Repository") }
|
||||
.all { configureRepository() }
|
||||
}
|
||||
|
||||
private fun Project.configureSigning() {
|
||||
val signingRequired = provider {
|
||||
project.findProperty("signingRequired")?.toString()?.toBoolean()
|
||||
?: project.property("isSonatypeRelease") as Boolean
|
||||
}
|
||||
|
||||
configure<SigningExtension> {
|
||||
setRequired(signingRequired)
|
||||
sign(extensions.getByType<PublishingExtension>().publications) // all publications
|
||||
useGpgCmd()
|
||||
}
|
||||
|
||||
tasks.withType<Sign>().configureEach {
|
||||
setOnlyIf { signingRequired.get() }
|
||||
}
|
||||
}
|
||||
|
||||
fun TaskProvider<PublishToMavenRepository>.configureRepository() =
|
||||
configure { configureRepository() }
|
||||
|
||||
private fun PublishToMavenRepository.configureRepository() {
|
||||
dependsOn(project.rootProject.tasks.named("preparePublication"))
|
||||
doFirst {
|
||||
val preparePublication = project.rootProject.tasks.named("preparePublication").get()
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import plugins.configureDefaultPublishing
|
||||
import plugins.configureKotlinPomAttributes
|
||||
import groovy.util.Node
|
||||
import groovy.util.NodeList
|
||||
|
||||
plugins {
|
||||
`kotlin-multiplatform` apply false
|
||||
base
|
||||
`maven-publish`
|
||||
signing
|
||||
}
|
||||
|
||||
open class ComponentsFactoryAccess
|
||||
@@ -248,42 +253,56 @@ val annotationsMetadataComponent = componentFactory.adhoc("annotations-common").
|
||||
}
|
||||
}
|
||||
|
||||
val emptyJavadocJar by tasks.creating(Jar::class) {
|
||||
archiveClassifier.set("javadoc")
|
||||
}
|
||||
|
||||
configureDefaultPublishing()
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create("main", MavenPublication::class) {
|
||||
from(rootComponent)
|
||||
artifact(combinedSourcesJar)
|
||||
// TODO: Remove all optional dependencies from root pom
|
||||
// Remove all optional dependencies from the root pom
|
||||
pom.withXml {
|
||||
val dependenciesNode = (asNode().get("dependencies") as NodeList).filterIsInstance<Node>().single()
|
||||
val optionalDependencies = (dependenciesNode.get("dependency") as NodeList).filterIsInstance<Node>().filter {
|
||||
((it.get("optional") as NodeList).singleOrNull() as Node?)?.text() == "true"
|
||||
}
|
||||
optionalDependencies.forEach { dependenciesNode.remove(it) }
|
||||
}
|
||||
configureKotlinPomAttributes(project, "Kotlin Test Multiplatform library")
|
||||
}
|
||||
jvmTestFrameworks.forEach { framework ->
|
||||
create(framework, MavenPublication::class) {
|
||||
artifactId = "kotlin-test-$framework"
|
||||
from(components[framework])
|
||||
artifact(tasks.getByPath(":kotlin-test:kotlin-test-$framework:sourcesJar") as Jar)
|
||||
configureKotlinPomAttributes(project, "Kotlin Test Support for $framework")
|
||||
}
|
||||
}
|
||||
create("js", MavenPublication::class) {
|
||||
artifactId = "kotlin-test-js"
|
||||
from(jsComponent)
|
||||
artifact(tasks.getByPath(":kotlin-test:kotlin-test-js:sourcesJar") as Jar)
|
||||
configureKotlinPomAttributes(project, "Kotlin Test for JS")
|
||||
}
|
||||
create("common", MavenPublication::class) {
|
||||
artifactId = "kotlin-test-common"
|
||||
from(commonMetadataComponent)
|
||||
artifact(tasks.getByPath(":kotlin-test:kotlin-test-common:sourcesJar") as Jar)
|
||||
configureKotlinPomAttributes(project, "Kotlin Test Common")
|
||||
}
|
||||
create("annotationsCommon", MavenPublication::class) {
|
||||
artifactId = "kotlin-test-annotations-common"
|
||||
from(annotationsMetadataComponent)
|
||||
artifact(tasks.getByPath(":kotlin-test:kotlin-test-annotations-common:sourcesJar") as Jar)
|
||||
configureKotlinPomAttributes(project, "Kotlin Test Common")
|
||||
}
|
||||
withType<MavenPublication> {
|
||||
suppressAllPomMetadataWarnings()
|
||||
artifact(emptyJavadocJar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
val install by creating {
|
||||
dependsOn(publishToMavenLocal)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user