Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 1 | import org.gradle.util.VersionNumber |
| 2 | |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 3 | /* |
Vsevolod Tolstopyatov | 6d1a6e3 | 2020-02-18 15:28:00 +0300 | [diff] [blame] | 4 | * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 7 | // Configures publishing of Maven artifacts to Bintray |
| 8 | |
| 9 | apply plugin: 'maven' |
| 10 | apply plugin: 'maven-publish' |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 11 | |
Roman Elizarov | 79e02bb | 2017-12-26 13:08:15 +0300 | [diff] [blame] | 12 | // ------------- tasks |
| 13 | |
Vsevolod Tolstopyatov | fe4e05c | 2019-07-19 12:28:15 +0300 | [diff] [blame] | 14 | def isMultiplatform = project.name == "kotlinx-coroutines-core" |
| 15 | def isBom = project.name == "kotlinx-coroutines-bom" |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 16 | def isKotlin137x = VersionNumber.parse(kotlin_version) <= VersionNumber.parse("1.3.79") |
Vsevolod Tolstopyatov | 4ddfc91 | 2018-07-12 18:36:02 +0300 | [diff] [blame] | 17 | |
Sergey Shatunov | c5a42da | 2019-09-22 19:50:35 +0700 | [diff] [blame] | 18 | if (!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 | |
| 27 | if (!isMultiplatform && !isBom) { |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 28 | // Regular java modules need 'java-library' plugin for proper publication |
| 29 | apply plugin: 'java-library' |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 30 | |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 31 | // MPP projects pack their sources automatically, java libraries need to explicitly pack them |
| 32 | task sourcesJar(type: Jar) { |
| 33 | archiveClassifier = 'sources' |
Vsevolod Tolstopyatov | 4ddfc91 | 2018-07-12 18:36:02 +0300 | [diff] [blame] | 34 | from sourceSets.main.allSource |
| 35 | } |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | publishing { |
Vsevolod Tolstopyatov | 4ddfc91 | 2018-07-12 18:36:02 +0300 | [diff] [blame] | 39 | repositories { |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 40 | 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 Tolstopyatov | 4ddfc91 | 2018-07-12 18:36:02 +0300 | [diff] [blame] | 51 | } |
| 52 | |
Sergey Shatunov | c5a42da | 2019-09-22 19:50:35 +0700 | [diff] [blame] | 53 | if (!isMultiplatform && !isBom) { |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 54 | // Configure java publications for regular non-MPP modules |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 55 | publications { |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 56 | maven(MavenPublication) { |
Vsevolod Tolstopyatov | 2f50363 | 2019-07-19 14:16:14 +0300 | [diff] [blame] | 57 | if (project.name == "kotlinx-coroutines-debug") { |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 58 | project.shadow.component(it) |
Vsevolod Tolstopyatov | 2f50363 | 2019-07-19 14:16:14 +0300 | [diff] [blame] | 59 | } else { |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 60 | from components.java |
Vsevolod Tolstopyatov | 2f50363 | 2019-07-19 14:16:14 +0300 | [diff] [blame] | 61 | } |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 62 | artifact sourcesJar |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 63 | } |
| 64 | } |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 65 | } |
| 66 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 67 | publications.all { |
Vsevolod Tolstopyatov | 0f15812 | 2020-04-29 23:35:41 +0300 | [diff] [blame] | 68 | MavenCentralKt.configureMavenCentralMetadata(pom, project) |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 69 | |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 70 | // add empty javadocs |
| 71 | if (!isBom && it.name != "kotlinMultiplatform") { |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 72 | it.artifact(javadocJar) |
| 73 | } |
| 74 | |
| 75 | // Rename MPP artifacts for backward compatibility |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 76 | def type = it.name |
| 77 | switch (type) { |
| 78 | case 'kotlinMultiplatform': |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 79 | // 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 Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 86 | break |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 87 | case 'metadata': |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 88 | // 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 Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 91 | break |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 92 | case 'jvm': |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 93 | it.artifactId = isKotlin137x ? project.name : "$project.name-jvm" |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 94 | break |
| 95 | case 'js': |
| 96 | case 'native': |
| 97 | it.artifactId = "$project.name-$type" |
| 98 | break |
| 99 | } |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 100 | // 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 Tolstopyatov | 3179683 | 2018-11-12 14:49:41 +0300 | [diff] [blame] | 106 | } |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 107 | |
Vsevolod Tolstopyatov | 3179683 | 2018-11-12 14:49:41 +0300 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
Sergey Igushkin | 17248c8 | 2020-05-22 12:28:25 +0300 | [diff] [blame] | 111 | tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach { |
| 112 | dependsOn(tasks["generatePomFileForJvmPublication"]) |
| 113 | } |
| 114 | |
Vsevolod Tolstopyatov | 3179683 | 2018-11-12 14:49:41 +0300 | [diff] [blame] | 115 | task publishDevelopSnapshot() { |
| 116 | def branch = System.getenv('currentBranch') |
Vsevolod Tolstopyatov | 3179683 | 2018-11-12 14:49:41 +0300 | [diff] [blame] | 117 | if (branch == "develop") { |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 118 | dependsOn(":publish") |
Vsevolod Tolstopyatov | 3179683 | 2018-11-12 14:49:41 +0300 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 122 | // Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload |
Sergey Shatunov | c5a42da | 2019-09-22 19:50:35 +0700 | [diff] [blame] | 123 | task bintrayUpload(dependsOn: publish) |