@@ -51,15 +51,15 @@ afterEvaluate {
51
51
52
52
publishing {
53
53
if (! isMultiplatform && ! isBom) {
54
- publications.withType <MavenPublication >().all {
54
+ publications.register <MavenPublication >(" maven " ) {
55
55
artifactId = project.name
56
56
from(components[" java" ])
57
57
artifact(mainSourcesJar)
58
58
artifact(tasks.named(" stubJavadoc" ))
59
59
}
60
60
} else {
61
61
// Rename artifacts for backward compatibility
62
- publications.withType( MavenPublication :: class ).all {
62
+ publications.withType< MavenPublication >().configureEach {
63
63
val type = name
64
64
logger.info(" Configuring $type " )
65
65
when (type) {
@@ -81,16 +81,49 @@ afterEvaluate {
81
81
}
82
82
}
83
83
84
- publications.withType( MavenPublication :: class ).all {
85
- pom.configureMavenCentralMetadata(project )
86
- signPublicationIfKeyPresent(project, this )
84
+ publications.withType< MavenPublication >().configureEach {
85
+ pom.configureMavenCentralMetadata()
86
+ signPublicationIfKeyPresent()
87
87
}
88
88
}
89
89
}
90
90
91
+ val testRepositoryDir = project.layout.buildDirectory.dir(" testRepository" )
92
+
91
93
publishing {
92
94
repositories {
93
- configureMavenPublication(this , project)
95
+ addSonatypeRepository()
96
+
97
+ /* *
98
+ * Maven repository in build directory to check published artifacts.
99
+ */
100
+ maven {
101
+ setUrl(testRepositoryDir)
102
+ name = " test"
103
+ }
104
+ }
105
+ }
106
+
107
+ interface LocalArtifactAttr : Named {
108
+ companion object {
109
+ val ATTRIBUTE = Attribute .of(
110
+ " kotlinx.kover.gradle-plugin" ,
111
+ LocalArtifactAttr ::class .java
112
+ )
113
+ }
114
+ }
115
+
116
+ val testPublicationTask: TaskCollection <* > = tasks.named { name -> name == " publishAllPublicationsToTestRepository" }
117
+ configurations.register(" testPublication" ) {
118
+ isVisible = false
119
+ isCanBeResolved = false
120
+ // this configuration produces modules that can be consumed by other projects
121
+ isCanBeConsumed = true
122
+ attributes {
123
+ attribute(Attribute .of(" kotlinx.serialization.repository" , String ::class .java), " test" )
124
+ }
125
+ outgoing.artifact(testRepositoryDir) {
126
+ builtBy(testPublicationTask)
94
127
}
95
128
}
96
129
@@ -119,7 +152,7 @@ tasks.register("bintrayUpload") {
119
152
dependsOn(tasks.publishToMavenLocal)
120
153
}
121
154
122
- fun MavenPom.configureMavenCentralMetadata (project : Project ) {
155
+ fun MavenPom.configureMavenCentralMetadata () {
123
156
name = project.name
124
157
description = " Kotlin multiplatform serialization runtime library"
125
158
url = " https://github.com/Kotlin/kotlinx.serialization"
@@ -158,7 +191,7 @@ fun MavenPom.configureMavenCentralMetadata(project: Project) {
158
191
*/
159
192
public fun Project.reconfigureMultiplatformPublication (jvmPublication : MavenPublication ) {
160
193
val mavenPublications =
161
- extensions.getByType( PublishingExtension :: class .java ).publications.withType<MavenPublication >()
194
+ extensions.getByType< PublishingExtension >( ).publications.withType<MavenPublication >()
162
195
val kmpPublication = mavenPublications.getByName(" kotlinMultiplatform" )
163
196
164
197
var jvmPublicationXml: XmlProvider ? = null
@@ -194,24 +227,24 @@ public fun Project.reconfigureMultiplatformPublication(jvmPublication: MavenPubl
194
227
}
195
228
}
196
229
197
- fun signPublicationIfKeyPresent (project : Project , publication : MavenPublication ) {
198
- val keyId = project. getSensitiveProperty(" libs.sign.key.id" )
199
- val signingKey = project. getSensitiveProperty(" libs.sign.key.private" )
200
- val signingKeyPassphrase = project. getSensitiveProperty(" libs.sign.passphrase" )
230
+ fun MavenPublication. signPublicationIfKeyPresent () {
231
+ val keyId = getSensitiveProperty(" libs.sign.key.id" )
232
+ val signingKey = getSensitiveProperty(" libs.sign.key.private" )
233
+ val signingKeyPassphrase = getSensitiveProperty(" libs.sign.passphrase" )
201
234
if (! signingKey.isNullOrBlank()) {
202
- project. extensions.configure<SigningExtension >(" signing" ) {
235
+ extensions.configure<SigningExtension >(" signing" ) {
203
236
useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
204
- sign(publication )
237
+ sign(this @signPublicationIfKeyPresent )
205
238
}
206
239
}
207
240
}
208
241
209
- fun configureMavenPublication ( rh : RepositoryHandler , project : Project ) {
210
- rh. maven {
242
+ fun RepositoryHandler. addSonatypeRepository ( ) {
243
+ maven {
211
244
url = mavenRepositoryUri()
212
245
credentials {
213
- username = project. getSensitiveProperty(" libs.sonatype.user" )
214
- password = project. getSensitiveProperty(" libs.sonatype.password" )
246
+ username = getSensitiveProperty(" libs.sonatype.user" )
247
+ password = getSensitiveProperty(" libs.sonatype.password" )
215
248
}
216
249
}
217
250
}
@@ -226,6 +259,6 @@ fun mavenRepositoryUri(): URI {
226
259
}
227
260
}
228
261
229
- fun Project. getSensitiveProperty (name : String ): String? {
230
- return project. findProperty(name) as ? String ? : System .getenv(name)
262
+ fun getSensitiveProperty (name : String ): String? {
263
+ return findProperty(name) as ? String ? : System .getenv(name)
231
264
}
0 commit comments