blob: b36c79763d8d24756d8ac217d0f0c39f22410f13 [file] [log] [blame]
Sergey Igushkin17248c82020-05-22 12:28:25 +03001import org.gradle.util.VersionNumber
2
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03003/*
Vsevolod Tolstopyatov6d1a6e32020-02-18 15:28:00 +03004 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03005 */
6
Roman Elizarov65eff0b2017-12-20 15:51:31 +03007// Configures publishing of Maven artifacts to Bintray
8
9apply plugin: 'maven'
10apply plugin: 'maven-publish'
Roman Elizarov65eff0b2017-12-20 15:51:31 +030011
Roman Elizarov79e02bb2017-12-26 13:08:15 +030012// ------------- tasks
13
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +030014def isMultiplatform = project.name == "kotlinx-coroutines-core"
15def isBom = project.name == "kotlinx-coroutines-bom"
Sergey Igushkin17248c82020-05-22 12:28:25 +030016def isKotlin137x = VersionNumber.parse(kotlin_version) <= VersionNumber.parse("1.3.79")
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +030017
Sergey Shatunovc5a42da2019-09-22 19:50:35 +070018if (!isBom) {
19 apply plugin: "com.github.johnrengelman.shadow"
20
21 // empty xxx-javadoc.jar
22 task javadocJar(type: Jar) {
23 archiveClassifier = 'javadoc'
24 }
25}
26
27if (!isMultiplatform && !isBom) {
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030028 // Regular java modules need 'java-library' plugin for proper publication
29 apply plugin: 'java-library'
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030030
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030031 // MPP projects pack their sources automatically, java libraries need to explicitly pack them
32 task sourcesJar(type: Jar) {
33 archiveClassifier = 'sources'
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +030034 from sourceSets.main.allSource
35 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030036}
37
38publishing {
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +030039 repositories {
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030040 maven {
41 def user = 'kotlin'
42 def repo = 'kotlinx'
43 def name = 'kotlinx.coroutines'
44 url = "https://api.bintray.com/maven/$user/$repo/$name/;publish=0"
45
46 credentials {
47 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
48 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
49 }
50 }
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +030051 }
52
Sergey Shatunovc5a42da2019-09-22 19:50:35 +070053 if (!isMultiplatform && !isBom) {
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030054 // Configure java publications for regular non-MPP modules
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030055 publications {
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030056 maven(MavenPublication) {
Vsevolod Tolstopyatov2f503632019-07-19 14:16:14 +030057 if (project.name == "kotlinx-coroutines-debug") {
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030058 project.shadow.component(it)
Vsevolod Tolstopyatov2f503632019-07-19 14:16:14 +030059 } else {
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030060 from components.java
Vsevolod Tolstopyatov2f503632019-07-19 14:16:14 +030061 }
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030062 artifact sourcesJar
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030063 }
64 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030065 }
66
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030067 publications.all {
Vsevolod Tolstopyatov0f158122020-04-29 23:35:41 +030068 MavenCentralKt.configureMavenCentralMetadata(pom, project)
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030069
Sergey Igushkin17248c82020-05-22 12:28:25 +030070 // add empty javadocs
71 if (!isBom && it.name != "kotlinMultiplatform") {
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030072 it.artifact(javadocJar)
73 }
74
75 // Rename MPP artifacts for backward compatibility
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030076 def type = it.name
77 switch (type) {
78 case 'kotlinMultiplatform':
Sergey Igushkin17248c82020-05-22 12:28:25 +030079 // With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with
80 // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too
81 it.artifactId = isKotlin137x ? "$project.name-native" : project.name
82 if (!isKotlin137x) {
83 apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle"
84 publishPlatformArtifactsInRootModule(publications["jvm"])
85 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030086 break
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030087 case 'metadata':
Sergey Igushkin17248c82020-05-22 12:28:25 +030088 // As the old -common dependencies will fail to resolve with Gradle module metadata, rename the module
89 // to '*-metadata' so that the resolution failure are more clear
90 it.artifactId = isKotlin137x ? "$project.name-common" : "$project.name-metadata"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030091 break
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030092 case 'jvm':
Sergey Igushkin17248c82020-05-22 12:28:25 +030093 it.artifactId = isKotlin137x ? project.name : "$project.name-jvm"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030094 break
95 case 'js':
96 case 'native':
97 it.artifactId = "$project.name-$type"
98 break
99 }
Sergey Igushkin17248c82020-05-22 12:28:25 +0300100 // Hierarchical project structures are not fully supported in 1.3.7x MPP
101 if (isKotlin137x) {
102 // disable metadata everywhere, but in native and js modules
103 if (type == 'maven' || type == 'metadata' || type == 'jvm') {
104 moduleDescriptorGenerator = null
105 }
Vsevolod Tolstopyatov31796832018-11-12 14:49:41 +0300106 }
Sergey Igushkin17248c82020-05-22 12:28:25 +0300107
Vsevolod Tolstopyatov31796832018-11-12 14:49:41 +0300108 }
109}
110
Sergey Igushkin17248c82020-05-22 12:28:25 +0300111tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
112 dependsOn(tasks["generatePomFileForJvmPublication"])
113}
114
Vsevolod Tolstopyatov31796832018-11-12 14:49:41 +0300115task publishDevelopSnapshot() {
116 def branch = System.getenv('currentBranch')
Vsevolod Tolstopyatov31796832018-11-12 14:49:41 +0300117 if (branch == "develop") {
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +0300118 dependsOn(":publish")
Vsevolod Tolstopyatov31796832018-11-12 14:49:41 +0300119 }
120}
121
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +0300122// Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload
Sergey Shatunovc5a42da2019-09-22 19:50:35 +0700123task bintrayUpload(dependsOn: publish)