[kotlin-test] Custom publishing layout KT-61969

This commit is contained in:
Ilya Gorbunov
2023-11-24 05:00:41 +01:00
committed by Space Team
parent ffe54d3fc4
commit b91e4e24c4
11 changed files with 163 additions and 13 deletions
+119 -1
View File
@@ -1,10 +1,13 @@
@file:Suppress("UNUSED_VARIABLE")
import org.gradle.api.publish.internal.PublicationInternal
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import plugins.configureDefaultPublishing
import plugins.configureKotlinPomAttributes
import plugins.publishing.*
plugins {
kotlin("multiplatform")
@@ -398,3 +401,118 @@ configurations {
}
}
}
configureDefaultPublishing()
fun emptyJavadocJar(appendix: String? = null): TaskProvider<Jar> =
tasks.register<Jar>("emptyJavadocJar${appendix.orEmpty().capitalize()}") {
archiveAppendix = appendix
archiveClassifier = "javadoc"
}
publishing {
val artifactBaseName = base.archivesName.get()
configureMultiModuleMavenPublishing {
val rootModule = module("rootModule") {
mavenPublication {
artifactId = artifactBaseName
configureKotlinPomAttributes(project, "Kotlin Test Multiplatform library")
artifact(emptyJavadocJar())
}
variant("metadataApiElements") { suppressPomMetadataWarnings() }
variant("jvmApiElements")
variant("jvmRuntimeElements") {
configureVariantDetails { mapToMavenScope("runtime") }
}
variant("jvmSourcesElements")
variant("nativeApiElements") {
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named("non-jvm"))
attribute(Usage.USAGE_ATTRIBUTE, objects.named(KotlinUsages.KOTLIN_API))
attribute(KotlinPlatformType.attribute, KotlinPlatformType.native)
}
}
}
val frameworkModules = jvmTestFrameworks.map { framework ->
module("${framework.lowercase()}Module") {
mavenPublication {
artifactId = "$artifactBaseName-${framework.lowercase()}"
configureKotlinPomAttributes(project, "Kotlin Test library support for ${framework}")
artifact(emptyJavadocJar(framework.lowercase()))
}
variant("jvm${framework}ApiElements") { suppressPomMetadataWarnings() }
variant("jvm${framework}RuntimeElements") {
suppressPomMetadataWarnings()
configureVariantDetails { mapToMavenScope("runtime") }
}
variant("jvm${framework}SourcesElements") { suppressPomMetadataWarnings() }
}
}
val js = module("jsModule") {
mavenPublication {
artifactId = "$artifactBaseName-js"
configureKotlinPomAttributes(project, "Kotlin Test library for JS", packaging = "klib")
}
variant("jsApiElements")
variant("jsRuntimeElements")
variant("jsSourcesElements")
}
val wasmJs = module("wasmJsModule") {
mavenPublication {
artifactId = "$artifactBaseName-wasm-js"
configureKotlinPomAttributes(project, "Kotlin Test library for experimental WebAssembly JS platform", packaging = "klib")
}
variant("wasmJsApiElements")
variant("wasmJsRuntimeElements")
variant("wasmJsSourcesElements")
}
val wasmWasi = module("wasmWasiModule") {
mavenPublication {
artifactId = "$artifactBaseName-wasm-wasi"
configureKotlinPomAttributes(project, "Kotlin Test library for experimental WebAssembly WASI platform", packaging = "klib")
}
variant("wasmWasiApiElements")
variant("wasmWasiRuntimeElements")
variant("wasmWasiSourcesElements")
}
module("testCommonModule") {
mavenPublication {
artifactId = "$artifactBaseName-common"
configureKotlinPomAttributes(project, "Legacy artifact of Kotlin Test library. Use kotlin-test instead", packaging = "pom")
(this as PublicationInternal<*>).isAlias = true
}
variant("kotlinTestCommonElements")
}
module("testAnnotationsCommonModule") {
mavenPublication {
artifactId = "$artifactBaseName-annotations-common"
configureKotlinPomAttributes(project, "Legacy artifact of Kotlin Test library. Use kotlin-test instead", packaging = "pom")
(this as PublicationInternal<*>).isAlias = true
}
variant("kotlinTestAnnotationsCommonElements")
}
// Makes all variants from accompanying artifacts visible through `available-at`
rootModule.include(js, *frameworkModules.toTypedArray(), wasmJs, wasmWasi)
}
publications {
(listOf(
listOf("rootModule", "Main", "kotlin-test", "jvmRuntimeClasspath"),
listOf("jsModule", "Js", "kotlin-test-js", "jsRuntimeClasspath"),
listOf("wasmJsModule", "Wasm-Js", "kotlin-test-wasm-js", "wasmJsRuntimeClasspath"),
listOf("wasmWasiModule", "Wasm-Wasi", "kotlin-test-wasm-wasi", "wasmWasiRuntimeClasspath"),
listOf("testCommonModule", "Common", "kotlin-test-common", "kotlinTestCommonDependencies"),
listOf("testAnnotationsCommonModule", "AnnotationsCommon", "kotlin-test-annotations-common", "kotlinTestAnnotationsCommonDependencies"),
) + jvmTestFrameworks.map { framework ->
listOf("${framework.lowercase()}Module", "$framework", "kotlin-test-${framework.lowercase()}", "jvm${framework}RuntimeDependencies")
}).forEach { (module, sbomTarget, sbomDocument, classpath) ->
configureSbom(sbomTarget, sbomDocument, setOf(classpath), named<MavenPublication>(module))
}
}
}
@@ -1,12 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-annotations-common</artifactId>
<version>ArtifactsTest.version</version>
<packaging>pom</packaging>
<name>Kotlin Test Annotations Common</name>
<description>Kotlin Test Common</description>
<description>Legacy artifact of Kotlin Test library. Use kotlin-test instead</description>
<url>https://kotlinlang.org/</url>
<licenses>
<license>
@@ -29,7 +35,7 @@
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<artifactId>kotlin-test</artifactId>
<version>ArtifactsTest.version</version>
<scope>compile</scope>
</dependency>
@@ -1,12 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-common</artifactId>
<version>ArtifactsTest.version</version>
<packaging>pom</packaging>
<name>Kotlin Test Common</name>
<description>Kotlin Test Common</description>
<description>Legacy artifact of Kotlin Test library. Use kotlin-test instead</description>
<url>https://kotlinlang.org/</url>
<licenses>
<license>
@@ -29,7 +35,7 @@
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<artifactId>kotlin-test</artifactId>
<version>ArtifactsTest.version</version>
<scope>compile</scope>
</dependency>
@@ -12,7 +12,7 @@
<version>ArtifactsTest.version</version>
<packaging>klib</packaging>
<name>Kotlin Test Js</name>
<description>Kotlin Test for JS</description>
<description>Kotlin Test library for JS</description>
<url>https://kotlinlang.org/</url>
<licenses>
<license>
@@ -11,7 +11,7 @@
<artifactId>kotlin-test-junit</artifactId>
<version>ArtifactsTest.version</version>
<name>Kotlin Test Junit</name>
<description>Kotlin Test Support for junit</description>
<description>Kotlin Test library support for JUnit</description>
<url>https://kotlinlang.org/</url>
<licenses>
<license>
@@ -11,7 +11,7 @@
<artifactId>kotlin-test-junit5</artifactId>
<version>ArtifactsTest.version</version>
<name>Kotlin Test Junit5</name>
<description>Kotlin Test Support for junit5</description>
<description>Kotlin Test library support for JUnit5</description>
<url>https://kotlinlang.org/</url>
<licenses>
<license>
@@ -11,7 +11,7 @@
<artifactId>kotlin-test-testng</artifactId>
<version>ArtifactsTest.version</version>
<name>Kotlin Test Testng</name>
<description>Kotlin Test Support for testng</description>
<description>Kotlin Test library support for TestNG</description>
<url>https://kotlinlang.org/</url>
<licenses>
<license>
@@ -12,7 +12,7 @@
<version>ArtifactsTest.version</version>
<packaging>klib</packaging>
<name>Kotlin Test Wasm Js</name>
<description>Kotlin Test for Wasm JS</description>
<description>Kotlin Test library for experimental WebAssembly JS platform</description>
<url>https://kotlinlang.org/</url>
<licenses>
<license>
@@ -12,7 +12,7 @@
<version>ArtifactsTest.version</version>
<packaging>klib</packaging>
<name>Kotlin Test Wasm Wasi</name>
<description>Kotlin Test for Wasm WASI</description>
<description>Kotlin Test library for experimental WebAssembly WASI platform</description>
<url>https://kotlinlang.org/</url>
<licenses>
<license>
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
@@ -30,6 +31,20 @@
<developerConnection>scm:git:https://github.com/JetBrains/kotlin.git</developerConnection>
<url>https://github.com/JetBrains/kotlin</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-common</artifactId>
<version>ArtifactsTest.version</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-annotations-common</artifactId>
<version>ArtifactsTest.version</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
@@ -71,6 +71,9 @@ class MultiModuleMavenPublishingConfiguration() {
fun configureVariantDetails(code: ConfigurationVariantDetails.() -> Unit) {
variantDetailsConfigurations += code
}
var suppressPomMetadataWarnings: Boolean = false
fun suppressPomMetadataWarnings() { suppressPomMetadataWarnings = true }
}
val mavenPublicationConfigurations = mutableListOf<MavenPublication.() -> Unit>()
@@ -124,6 +127,9 @@ fun Project.configureMultiModuleMavenPublishing(code: MultiModuleMavenPublishing
from(component)
val module = publishingConfiguration.modules[componentName]!!
module.mavenPublicationConfigurations.forEach { configure -> configure() }
module.variants.values.filter { it.suppressPomMetadataWarnings }.forEach {
suppressPomMetadataWarningsFor(it.name)
}
}
}
}
@@ -145,7 +151,6 @@ fun Project.addVariant(component: AdhocComponentWithVariants, variant: MultiModu
val configuration = configurations.getOrCreate(variant.configurationName)
configuration.apply {
isCanBeResolved = false
isCanBeConsumed = true
variant.attributesConfigurations.forEach { configure -> attributes.configure() }
}