From 3e4cbd6dd2460a567cbcf4f72b288a2ba4ff7ec9 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 8 Aug 2023 17:18:54 +0200 Subject: [PATCH] Publish Gradle metadata for kotlin-stdlib-common, KT-60911 This makes it depend on kotlin-stdlib in all targets and have no artifacts from Gradle's point of view --- libraries/stdlib/common/build.gradle | 45 ++++++++++++++++++- .../kotlin-stdlib-common.pom | 16 ++++++- .../plugins/KotlinBuildPublishingPlugin.kt | 3 ++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/libraries/stdlib/common/build.gradle b/libraries/stdlib/common/build.gradle index 384ec09ee9a..53738f0a6df 100644 --- a/libraries/stdlib/common/build.gradle +++ b/libraries/stdlib/common/build.gradle @@ -1,11 +1,10 @@ plugins { id("kotlin-platform-common") + id("maven-publish") } description = 'Kotlin Common Standard Library' -RepoArtifacts.publish(project) - JvmToolchain.updateJvmTarget(project, "1.8") def commonSrcDir = "../src" @@ -76,3 +75,45 @@ RepoArtifacts.javadocJar(project) tasks.named("sourcesJar").configure { it.dependsOn(":prepare:build.version:writeStdlibVersion") } classes.setDependsOn(classes.dependsOn.findAll { it != "compileJava" }) + +def stdlibCommonElements = configurations.create("stdlibCommonElements") { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) + } +} +dependencies { + add(stdlibCommonElements.name, project(":kotlin-stdlib")) +} + +class ComponentsFactoryAccess { + SoftwareComponentFactory factory + + @javax.inject.Inject + ComponentsFactoryAccess(SoftwareComponentFactory factory) { + this.factory = factory + } +} + +SoftwareComponentFactory componentFactory = objects.newInstance(ComponentsFactoryAccess).factory + +def rootComponent = componentFactory.adhoc("root") +rootComponent.addVariantsFromConfiguration(stdlibCommonElements) { + mapToOptional() +} + +plugins.KotlinBuildPublishingPluginKt.configureDefaultPublishing(project) + +publishing { + publications { + def mainPublication = register("main", MavenPublication) { + from(rootComponent) + artifact(jar) + artifact(sourcesJar) + artifact(javadocJar) + plugins.KotlinBuildPublishingPluginKt.configureKotlinPomAttributes(it, project, "Kotlin Common Standard Library (legacy, use kotlin-stdlib instead)", "jar") + } + SbomKt.configureSbom(project, "Main", "kotlin-stdlib-common", ["compileClasspath"], mainPublication) + } +} \ No newline at end of file diff --git a/repo/artifacts-tests/src/test/resources/org/jetbrains/kotlin/kotlin-stdlib-common/kotlin-stdlib-common.pom b/repo/artifacts-tests/src/test/resources/org/jetbrains/kotlin/kotlin-stdlib-common/kotlin-stdlib-common.pom index e18c52d5b82..7fb85f86b99 100644 --- a/repo/artifacts-tests/src/test/resources/org/jetbrains/kotlin/kotlin-stdlib-common/kotlin-stdlib-common.pom +++ b/repo/artifacts-tests/src/test/resources/org/jetbrains/kotlin/kotlin-stdlib-common/kotlin-stdlib-common.pom @@ -1,11 +1,16 @@ + + + + + 4.0.0 org.jetbrains.kotlin kotlin-stdlib-common ArtifactsTest.version Kotlin Stdlib Common - Kotlin Common Standard Library + Kotlin Common Standard Library (legacy, use kotlin-stdlib instead) https://kotlinlang.org/ @@ -25,4 +30,13 @@ scm:git:https://github.com/JetBrains/kotlin.git https://github.com/JetBrains/kotlin + + + org.jetbrains.kotlin + kotlin-stdlib + ArtifactsTest.version + compile + true + + diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt index b72c4b01d1b..57bb54e21c9 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt @@ -135,6 +135,9 @@ val Project.signLibraryPublication: Boolean ?: project.providers.gradleProperty("isSonatypeRelease").orNull?.toBoolean() ?: false +// overload for Groovy +fun Project.configureDefaultPublishing() = configureDefaultPublishing(signingRequired = signLibraryPublication) + fun Project.configureDefaultPublishing( signingRequired: Boolean = signLibraryPublication ) {