1/* 2 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5import org.gradle.util.VersionNumber 6 7// Configures publishing of Maven artifacts to Maven Central 8 9apply plugin: 'maven-publish' 10apply plugin: 'signing' 11 12// ------------- tasks 13 14def isMultiplatform = project.name == "kotlinx-coroutines-core" || project.name == "kotlinx-coroutines-test" 15def isBom = project.name == "kotlinx-coroutines-bom" 16 17if (!isBom) { 18 if (project.name == "kotlinx-coroutines-debug") { 19 apply plugin: "com.github.johnrengelman.shadow" 20 } 21 22 // empty xxx-javadoc.jar 23 task javadocJar(type: Jar) { 24 archiveClassifier = 'javadoc' 25 } 26} 27 28if (!isMultiplatform && !isBom) { 29 // Regular java modules need 'java-library' plugin for proper publication 30 apply plugin: 'java-library' 31 32 // MPP projects pack their sources automatically, java libraries need to explicitly pack them 33 task sourcesJar(type: Jar) { 34 archiveClassifier = 'sources' 35 from sourceSets.main.allSource 36 } 37} 38 39publishing { 40 repositories { 41 PublishingKt.configureMavenPublication(delegate, project) 42 } 43 44 if (!isMultiplatform && !isBom) { 45 // Configure java publications for regular non-MPP modules 46 publications { 47 maven(MavenPublication) { 48 from components.java 49 artifact sourcesJar 50 } 51 } 52 } 53 54 publications.all { 55 PublishingKt.configureMavenCentralMetadata(pom, project) 56 PublishingKt.signPublicationIfKeyPresent(project, it) 57 // add empty javadocs 58 if (!isBom && it.name != "kotlinMultiplatform") { 59 it.artifact(javadocJar) 60 } 61 62 def type = it.name 63 switch (type) { 64 case 'kotlinMultiplatform': 65 // With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with 66 // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too 67 it.artifactId = project.name 68 apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle" 69 publishPlatformArtifactsInRootModule(publications["jvm"]) 70 break 71 case 'metadata': 72 case 'jvm': 73 case 'js': 74 case 'native': 75 it.artifactId = "$project.name-$type" 76 break 77 } 78 } 79} 80 81tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach { 82 dependsOn(tasks["generatePomFileForJvmPublication"]) 83} 84 85// Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload 86task bintrayUpload(dependsOn: publish) 87