11import com.google.cloud.tools.jib.gradle.JibExtension
2+ import com.vanniktech.maven.publish.SonatypeHost
23import common.*
34import java.time.Year
45import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
56
6- plugins {
7- `maven- publish`
8- signing
9- com.gradleup.nmcp
10- }
7+ plugins { com.vanniktech.maven.publish }
118
129group = libs.versions.group.get()
1310
@@ -31,99 +28,55 @@ publishing {
3128 publications {
3229 // Kotlin Multiplatform
3330 pluginManager.withPlugin(" org.jetbrains.kotlin.multiplatform" ) {
34- val javadocJar by
35- tasks.registering(Jar ::class ) {
36- archiveClassifier = " javadoc"
37- duplicatesStrategy = DuplicatesStrategy .WARN
38- // Contents are deliberately left empty
39- // from(tasks.named("dokkaJavadoc"))
40- }
41-
42- // KMP will automatically create the publications
43- withType<MavenPublication >().configureEach {
44- artifact(javadocJar)
45- configurePom()
46- }
31+ // withType<MavenPublication>().configureEach { artifact(taskName..) }
4732 }
4833
4934 // Kotlin JVM ("org.jetbrains.kotlin.jvm")
5035 pluginManager.withPlugin(" java" ) {
51- register<MavenPublication >(" maven" ) {
52- from(components[" java" ])
53- configurePom()
54- }
36+ register<MavenPublication >(" maven" ) { from(components[" java" ]) }
5537
56- // Add an executable artifact if exists
5738 withType<MavenPublication >().configureEach {
5839 // configurations.findByName("customFile")?.artifacts?.forEach { artifact(it) }
5940
41+ // Add an executable artifact if exists
6042 // val execJar = tasks.findByName("buildExecutable") as? ReallyExecJar
61- // if (execJar != null) {
62- // artifact(execJar.execJarFile)
63- // }
43+ // if (execJar != null) { artifact(execJar.execJarFile) }
6444 }
6545 }
6646
6747 // Java Platform (BOM)
6848 pluginManager.withPlugin(" java-platform" ) {
69- register<MavenPublication >(" maven" ) {
70- from(components[" javaPlatform" ])
71- configurePom()
72- }
49+ register<MavenPublication >(" maven" ) { from(components[" javaPlatform" ]) }
7350 }
7451
7552 // Gradle version catalog
7653 pluginManager.withPlugin(" version-catalog" ) {
77- register<MavenPublication >(" maven" ) {
78- from(components[" versionCatalog" ])
79- configurePom()
80- }
54+ register<MavenPublication >(" maven" ) { from(components[" versionCatalog" ]) }
8155 }
8256
83- // Add Dokka html doc to all publications
84- pluginManager.withPlugin(" org.jetbrains.dokka" ) {
85- val dokkaGenerateJar by
86- tasks.registering(Jar ::class ) {
87- from(tasks.named(" dokkaGenerate" ))
88- archiveClassifier = " html-docs"
57+ // Configures GHCR credentials for Jib
58+ pluginManager.withPlugin(" com.google.cloud.tools.jib" ) {
59+ configure<JibExtension > {
60+ to {
61+ if (image.orEmpty().startsWith(" ghcr.io" , ignoreCase = true )) {
62+ auth {
63+ username = githubPackagesUsername.orNull
64+ password = githubPackagesPassword.orNull
65+ }
8966 }
90-
91- withType<MavenPublication >().configureEach { artifact(dokkaGenerateJar) }
92- }
93- }
94- }
95-
96- // Configures GHCR credentials for Jib
97- pluginManager.withPlugin(" com.google.cloud.tools.jib" ) {
98- configure<JibExtension > {
99- to {
100- if (image.orEmpty().startsWith(" ghcr.io" , ignoreCase = true )) {
101- auth {
102- username = githubPackagesUsername.orNull
103- password = githubPackagesPassword.orNull
10467 }
10568 }
10669 }
10770 }
10871}
10972
110- signing {
111- setRequired { hasSigningKey }
112- if (hasSigningKey) {
113- useInMemoryPgpKeys(
114- signingInMemoryKeyId.orNull, signingInMemoryKey.orNull, signingInMemoryKeyPassword.orNull)
115- sign(publishing.publications)
116- }
117- }
73+ mavenPublishing {
74+ publishToMavenCentral(host = SonatypeHost .CENTRAL_PORTAL , automaticRelease = true )
11875
119- nmcp {
120- centralPortal {
121- username = mavenCentralUsername
122- password = mavenCentralPassword
76+ if (hasSigningKey) {
77+ signAllPublications()
12378 }
124- }
12579
126- fun MavenPublication.configurePom () {
12780 pom {
12881 name = provider { " ${project.group} :${project.name} " }
12982 description = provider { project.description }
0 commit comments