| /* |
| * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| */ |
| |
| // Configures publishing of Maven artifacts to MavenCentral |
| |
| apply plugin: 'maven-publish' |
| apply plugin: 'signing' |
| |
| apply from: project.rootProject.file('gradle/maven-metadata.gradle') |
| |
| def isMultiplatform = project.name in ["kotlinx-serialization-core", "kotlinx-serialization-json", "kotlinx-serialization-json-okio", |
| "kotlinx-serialization-json-tests", "kotlinx-serialization-protobuf", "kotlinx-serialization-cbor", |
| "kotlinx-serialization-properties"] |
| def isBom = project.name == "kotlinx-serialization-bom" |
| |
| if (!isBom) { |
| task stubSources(type: Jar) { |
| archiveClassifier = 'sources' |
| } |
| |
| task stubJavadoc(type: Jar) { |
| archiveClassifier = 'javadoc' |
| } |
| } |
| |
| task emptyJar(type: Jar) { |
| } |
| |
| afterEvaluate { |
| task mainSourcesJar(type: Jar) { |
| classifier = 'sources' |
| if (isMultiplatform) { |
| from kotlin.sourceSets.commonMain.kotlin |
| } else { |
| from sourceSets.main.allSource |
| } |
| } |
| } |
| |
| afterEvaluate { |
| publishing { |
| def variantName = "${project.name}" |
| |
| if (!isMultiplatform && !isBom) { |
| publications { |
| maven(MavenPublication) { publication -> |
| artifactId variantName |
| publication.from components.java |
| publication.artifact mainSourcesJar |
| artifact stubJavadoc |
| |
| PublishingKt.configureMavenCentralMetadata(publication.pom, project) |
| PublishingKt.signPublicationIfKeyPresent(project, publication) |
| } |
| } |
| |
| return |
| } |
| |
| // Rename artifacts for backward compatibility |
| publications.all { |
| def type = it.name |
| logger.info("Configuring $type") |
| switch (type) { |
| case 'kotlinMultiplatform': |
| // With Kotlin 1.4.0, the root module ID has no suffix, but for compatibility with |
| // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it |
| it.artifactId = variantName |
| apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle" |
| publishPlatformArtifactsInRootModule(publications["jvm"]) |
| break |
| case 'metadata': |
| case 'jvm': |
| case 'js': |
| it.artifactId = "$variantName-$type" |
| break |
| } |
| logger.info("Artifact id = ${it.artifactId}") |
| |
| PublishingKt.configureMavenCentralMetadata(pom, project) |
| PublishingKt.signPublicationIfKeyPresent(project, it) |
| |
| // The 'root' module publishes the JVM module's Javadoc JAR as per publishPlatformArtifactsInRootModule, and |
| // every other module should publish an empty Javadoc JAR. TODO: provide proper documentation artifacts? |
| if (name != "kotlinMultiplatform" && !isBom) { |
| artifact stubJavadoc |
| } |
| } |
| } |
| } |
| |
| publishing { |
| repositories { |
| PublishingKt.configureMavenPublication(delegate, project) |
| } |
| } |
| |
| // Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload |
| task bintrayUpload(dependsOn: publish) |
| |
| // This is required for K/N publishing |
| bintrayUpload.dependsOn publishToMavenLocal |
| |