1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*
* Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
// Configures publishing of Maven artifacts to MavenCentral
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply from: project.rootProject.file('gradle/maven-metadata.gradle')
def isMultiplatform = project.name in ["kotlinx-serialization-core", "kotlinx-serialization-json", "kotlinx-serialization-json-okio",
"kotlinx-serialization-json-tests", "kotlinx-serialization-protobuf", "kotlinx-serialization-cbor",
"kotlinx-serialization-properties"]
def isBom = project.name == "kotlinx-serialization-bom"
if (!isBom) {
task stubSources(type: Jar) {
archiveClassifier = 'sources'
}
task stubJavadoc(type: Jar) {
archiveClassifier = 'javadoc'
}
}
task emptyJar(type: Jar) {
}
afterEvaluate {
task mainSourcesJar(type: Jar) {
classifier = 'sources'
if (isMultiplatform) {
from kotlin.sourceSets.commonMain.kotlin
} else if (isBom) {
// no-op: sourceSets is [] for BOM, as it does not have sources.
} else {
from sourceSets.main.allSource
}
}
}
afterEvaluate {
publishing {
def variantName = "${project.name}"
if (!isMultiplatform && !isBom) {
publications {
maven(MavenPublication) { publication ->
artifactId variantName
publication.from components.java
publication.artifact mainSourcesJar
artifact stubJavadoc
PublishingKt.configureMavenCentralMetadata(publication.pom, project)
PublishingKt.signPublicationIfKeyPresent(project, publication)
}
}
return
}
// Rename artifacts for backward compatibility
publications.all {
def type = it.name
logger.info("Configuring $type")
switch (type) {
case 'kotlinMultiplatform':
// With Kotlin 1.4.0, the root module ID has no suffix, but for compatibility with
// the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it
it.artifactId = variantName
apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle"
publishPlatformArtifactsInRootModule(publications["jvm"])
break
case 'metadata':
case 'jvm':
case 'js':
it.artifactId = "$variantName-$type"
break
}
logger.info("Artifact id = ${it.artifactId}")
PublishingKt.configureMavenCentralMetadata(pom, project)
PublishingKt.signPublicationIfKeyPresent(project, it)
// The 'root' module publishes the JVM module's Javadoc JAR as per publishPlatformArtifactsInRootModule, and
// every other module should publish an empty Javadoc JAR. TODO: provide proper documentation artifacts?
if (name != "kotlinMultiplatform" && !isBom) {
artifact stubJavadoc
}
}
}
}
publishing {
repositories {
PublishingKt.configureMavenPublication(delegate, project)
}
}
// Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload
task bintrayUpload(dependsOn: publish)
// This is required for K/N publishing
bintrayUpload.dependsOn publishToMavenLocal
|