1
1
/*
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.
3
3
*/
4
4
5
5
// Configures publishing of Maven artifacts to Bintray
6
6
7
7
apply plugin : ' maven'
8
8
apply plugin : ' maven-publish'
9
- apply plugin : ' com.jfrog.bintray'
10
9
apply plugin : " com.github.johnrengelman.shadow"
11
10
12
11
apply from : project. rootProject. file(' gradle/maven-central.gradle' )
13
12
14
13
// ------------- tasks
15
14
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' )
18
15
def isMultiplatform = project. name == " kotlinx-coroutines-core"
19
16
def isBom = project. name == " kotlinx-coroutines-bom"
20
17
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'
31
21
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'
37
25
from sourceSets. main. allSource
38
26
}
39
27
}
40
28
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'
63
32
}
64
33
65
34
publishing {
66
35
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
+ }
68
47
}
69
48
70
49
if (isBom) {
50
+ // Configure mavenBom publication
71
51
publications {
72
- mavenBom(MavenPublication ) {
73
- pom. withXml(configureMavenCentralMetadata)
74
- }
52
+ mavenBom(MavenPublication ) {}
75
53
}
76
- return
77
54
} else if (! isMultiplatform) {
55
+ // Configure java publications for regular non-MPP modules
78
56
publications {
79
- maven(MavenPublication ) { publication ->
80
- publication. artifact javadocJar
81
- publication. artifact sourcesJar
82
- publication. pom. withXml(configureMavenCentralMetadata)
57
+ maven(MavenPublication ) {
83
58
if (project. name == " kotlinx-coroutines-debug" ) {
84
- project. shadow. component(publication)
85
- publication. pom. withXml(configureMavenDependencies)
59
+ project. shadow. component(it)
86
60
} else {
87
- publication . from components. java
61
+ from components. java
88
62
}
63
+ artifact sourcesJar
89
64
}
90
65
}
91
-
92
- disableMetadataPublicationKotlinJvm()
93
- return
94
66
}
95
67
96
- // Rename artifacts for backward compatibility
97
68
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
98
77
def type = it. name
99
78
switch (type) {
100
79
case ' kotlinMultiplatform' :
101
80
it. artifactId = " $project . name -native"
102
- it. artifact emptyJar
103
- it. artifact stubJavadoc
104
- it. artifact sourcesJar
105
81
break
106
-
107
82
case ' metadata' :
108
83
it. artifactId = " $project . name -common"
109
84
break
110
-
111
85
case ' jvm' :
112
86
it. artifactId = " $project . name "
113
87
break
@@ -117,71 +91,19 @@ publishing {
117
91
break
118
92
}
119
93
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
150
97
}
151
98
}
152
99
}
153
100
154
101
task publishDevelopSnapshot () {
155
102
def branch = System . getenv(' currentBranch' )
156
103
if (branch == " develop" ) {
157
- dependsOn(" :artifactoryPublish " )
104
+ dependsOn(" :publish " )
158
105
}
159
106
}
160
107
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