Can anyone recommend a good plugin + example to pu...
# gradle
o
Can anyone recommend a good plugin + example to publish a lib to maven central (with gradle kts file)
for now I found this which I hope is up to date: https://chris.banes.dev/publishing-to-maven-central/
v
I usually use just the standard
maven-publish
plugin, with the https://github.com/gradle-nexus/publish-plugin plugin for some sugar, more reliable uploading and automatic closing and / or releasing.
3
j
Copy code
// buildSrc/src/main/kotlin/publish-kotlin-jvm.gradle.kts
// Apply this plugin to the Kotlin JVM module should be published

plugins {
    `maven-publish`
    signing
    id("org.jetbrains.dokka")
}

val docsJar by project.tasks.creating(Jar::class) {
    group = "build"
    description = "Assembles Javadoc jar file from for publishing"
    archiveClassifier.set("javadoc")
    dependsOn(tasks.named<DokkaTask>("dokkaHtml"))
}

val sourcesJar by project.tasks.creating(Jar::class) {
    group = "build"
    description = "Assembles Sources jar file for publishing"
    archiveClassifier.set("sources")
    from((project.properties["sourceSets"] as SourceSetContainer)["main"].allSource)
}

publishing {
    publications {
        withType<MavenPublication> {
            pom {
                name.set(property("pomName").toString())
                description.set(property("pomDescription").toString())
                url.set(property("pomUrl").toString())

                licenses {
                    license {
                        name.set(property("pomLicenseName").toString())
                        url.set(property("pomLicenseUrl").toString())
                    }
                }

                developers {
                    developer {
                        id.set(property("pomDeveloperId").toString())
                        name.set(property("pomDeveloperName").toString())
                        email.set(property("pomDeveloperEmail").toString())
                    }
                }

                scm {
                    url.set(property("pomSmcUrl").toString())
                    connection.set(property("pomSmcConnection").toString())
                    developerConnection.set(property("pomSmcDeveloperConnection").toString())
                }
            }

            artifact(docsJar)

            artifact(sourcesJar)
        }
        create<MavenPublication>("maven") { from(components["java"]) }
    }
}

signing {
    if (!project.version.toString().endsWith("-SNAPSHOT")) {
        useGpgCmd()
        sign(publishing.publications)
    }
}
Copy code
// buildSrc/src/main/kotlin/nexus.gradle.kts
// Apply this plugin to the root project in the root build.gradle.kts

plugins {
    id("io.github.gradle-nexus.publish-plugin")
}

nexusPublishing {
    repositories {
        sonatype {
            username.set("${properties["oss.user"] ?: System.getenv("OSS_USER")}")
            password.set("${properties["oss.token"] ?: System.getenv("OSS_TOKEN")}")
            stagingProfileId.set(
                "${properties["oss.stagingProfileId"] ?: System.getenv("OSS_STAGING_PROFILE_ID")}",
            )
        }
    }
}
The code is a bit different among all different types of modules (JVM, Android, Multiplatform). What is your project?
Ah, with my precompiled plugin you need to add this too (with your project values)
Copy code
// gradle.properties

pomName=Gradle Plugins
pomDescription=Gradle Plugins utilities
pomUrl=<https://github.com/JavierSegoviaCordoba/gradle-plugins>
pomLicenseName=The Apache License, Version 2.0
pomLicenseUrl="<https://www.apache.org/licenses/LICENSE-2.0.txt>"
pomDeveloperId=JavierSegoviaCordoba
pomDeveloperName=Javier Segovia Cordoba
pomDeveloperEmail=javier@segoviacordoba.com
pomSmcUrl=<https://github.com/JavierSegoviaCordoba/gradle-plugins>
pomSmcConnection=scm:git:git@github.com:JavierSegoviaCordoba/gradle-plugins.git
pomSmcDeveloperConnection=scm:git:git@github.com:JavierSegoviaCordoba/gradle-plugins.git
o
Thanks!