11/*
2- * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+ * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33 */
44
55// Configures publishing of Maven artifacts to Bintray
66
77apply plugin : ' maven'
88apply plugin : ' maven-publish'
9- apply plugin : ' com.jfrog.bintray'
109apply plugin : " com.github.johnrengelman.shadow"
1110
1211apply from : project. rootProject. file(' gradle/maven-central.gradle' )
1312
1413// ------------- tasks
1514
16- def bUser = project. hasProperty(' bintrayUser' ) ? project. property(' bintrayUser' ) : System . getenv(' BINTRAY_USER' )
17- def bKey = project. hasProperty(' bintrayApiKey' ) ? project. property(' bintrayApiKey' ) : System . getenv(' BINTRAY_API_KEY' )
1815def isMultiplatform = project. name == " kotlinx-coroutines-core"
1916def isBom = project. name == " kotlinx-coroutines-bom"
2017
21- task stubSources (type : Jar ) {
22- classifier = ' sources'
23- }
24-
25- task stubJavadoc (type : Jar ) {
26- classifier = ' javadoc'
27- }
28-
29- task emptyJar (type : Jar ) {
30- }
18+ if (! isMultiplatform) {
19+ // Regular java modules need 'java-library' plugin for proper publication
20+ apply plugin : ' java-library'
3121
32- task sourcesJar (type : Jar ) {
33- classifier = ' sources'
34- if (project. name == " kotlinx-coroutines-core" ) {
35- from kotlin. sourceSets. commonMain. kotlin
36- } else if (! isBom) {
22+ // MPP projects pack their sources automatically, java libraries need to explicitly pack them
23+ task sourcesJar(type : Jar ) {
24+ archiveClassifier = ' sources'
3725 from sourceSets. main. allSource
3826 }
3927}
4028
41- def configureTransitiveDependencies = { Project project , Publication publication ->
42- project. configure(project) {
43- publication. pom. withXml { pom ->
44- def dependenciesNode = asNode(). getAt(" dependencies" )[0 ]
45- if (dependenciesNode == null ) return
46- dependenciesNode. dependency. each {
47- it. artifactId. each { node ->
48- def artifactId = node. text()
49- if (! artifactId. endsWith(" native" )) return
50-
51- switch (project. name) {
52- case ' metadata' :
53- node. setValue(" ${ artifactId[0..-8]} -common" )
54- break
55- case ' js' :
56- node. setValue(" ${ artifactId[0..-8]} -js" )
57- break
58- }
59- }
60- }
61- }
62- }
29+ // empty xxx-javadoc.jar
30+ task javadocJar (type : Jar ) {
31+ archiveClassifier = ' javadoc'
6332}
6433
6534publishing {
6635 repositories {
67- maven { url = ' https://kotlin.bintray.com/kotlinx' }
36+ maven {
37+ def user = ' kotlin'
38+ def repo = ' kotlinx'
39+ def name = ' kotlinx.coroutines'
40+ url = " https://api.bintray.com/maven/$user /$repo /$name /;publish=0"
41+
42+ credentials {
43+ username = project. hasProperty(' bintrayUser' ) ? project. property(' bintrayUser' ) : System . getenv(' BINTRAY_USER' )
44+ password = project. hasProperty(' bintrayApiKey' ) ? project. property(' bintrayApiKey' ) : System . getenv(' BINTRAY_API_KEY' )
45+ }
46+ }
6847 }
6948
7049 if (isBom) {
50+ // Configure mavenBom publication
7151 publications {
72- mavenBom(MavenPublication ) {
73- pom. withXml(configureMavenCentralMetadata)
74- }
52+ mavenBom(MavenPublication ) {}
7553 }
76- return
7754 } else if (! isMultiplatform) {
55+ // Configure java publications for regular non-MPP modules
7856 publications {
79- maven(MavenPublication ) { publication ->
80- publication. artifact javadocJar
81- publication. artifact sourcesJar
82- publication. pom. withXml(configureMavenCentralMetadata)
57+ maven(MavenPublication ) {
8358 if (project. name == " kotlinx-coroutines-debug" ) {
84- project. shadow. component(publication)
85- publication. pom. withXml(configureMavenDependencies)
59+ project. shadow. component(it)
8660 } else {
87- publication . from components. java
61+ from components. java
8862 }
63+ artifact sourcesJar
8964 }
9065 }
91-
92- disableMetadataPublicationKotlinJvm()
93- return
9466 }
9567
96- // Rename artifacts for backward compatibility
9768 publications. all {
69+ pom. withXml(configureMavenCentralMetadata)
70+
71+ // add empty javadocs (no need for MPP root publication which publishes only pom file)
72+ if (it. name != ' kotlinMultiplatform' && ! isBom) {
73+ it. artifact(javadocJar)
74+ }
75+
76+ // Rename MPP artifacts for backward compatibility
9877 def type = it. name
9978 switch (type) {
10079 case ' kotlinMultiplatform' :
10180 it. artifactId = " $project . name -native"
102- it. artifact emptyJar
103- it. artifact stubJavadoc
104- it. artifact sourcesJar
10581 break
106-
10782 case ' metadata' :
10883 it. artifactId = " $project . name -common"
10984 break
110-
11185 case ' jvm' :
11286 it. artifactId = " $project . name "
11387 break
@@ -117,71 +91,19 @@ publishing {
11791 break
11892 }
11993
120- pom. withXml(configureMavenCentralMetadata)
121- configureTransitiveDependencies(project, it)
122- }
123-
124- disableMetadataPublication()
125- }
126-
127- private void disableMetadataPublicationKotlinJvm () {
128- publishing. publications. each { pub ->
129- pub. moduleDescriptorGenerator = null
130- tasks. matching { it. name == " generateMetadataFileFor${ pub.name.capitalize()} Publication" }. all {
131- onlyIf { false }
132- }
133- }
134- }
135-
136- private void disableMetadataPublication () {
137- kotlin. targets. all { target ->
138- def publication = publishing. publications. findByName(target. name)
139-
140- if (publication != null ) {
141- publication. artifact stubJavadoc
142- if (target. platformType. name != ' native' ) {
143- publication. moduleDescriptorGenerator = null
144- tasks. matching { it. name == " generateMetadataFileFor${ name.capitalize()} Publication" }. all {
145- onlyIf { false }
146- }
147- } else {
148- publication. artifact emptyJar
149- }
94+ // disable metadata everywhere, but in native modules
95+ if (type == ' maven' || type == ' metadata' || type == ' jvm' || type == ' js' ) {
96+ moduleDescriptorGenerator = null
15097 }
15198 }
15299}
153100
154101task publishDevelopSnapshot () {
155102 def branch = System . getenv(' currentBranch' )
156103 if (branch == " develop" ) {
157- dependsOn(" :artifactoryPublish " )
104+ dependsOn(" :publish " )
158105 }
159106}
160107
161- bintray {
162- user = bUser
163- key = bKey
164- override = true // for multi-platform Kotlin/Native publishing
165- publications = [' maven' ]
166- pkg {
167- userOrg = ' kotlin'
168- repo = ' kotlinx'
169- name = ' kotlinx.coroutines'
170- version {
171- name = project. version
172- vcsTag = project. version
173- released = new Date ()
174- }
175- }
176- }
177-
178- // TODO :kludge this is required for K/N publishing
179- bintrayUpload. dependsOn publishToMavenLocal
180-
181- // This is for easier debugging of bintray uploading problems
182- bintrayUpload. doFirst {
183- publications = project. publishing. publications. findAll { ! it. name. contains(' -test' ) }. collect {
184- println (" Uploading artifact '$it . groupId :$it . artifactId :$it . version ' from publication '$it . name '" )
185- it
186- }
187- }
108+ // Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload
109+ task bintrayUpload (dependsOn : publish)
0 commit comments