kotlingradlemaven-central

`Unresolved reference: sonatype` when using JReleaser to Publish to Central


I'm trying to publish a Kotlin Multiplatform library using JReleaser and the Portal Publisher API according to their tutorial, but when I try to translate the Groovy example to Kotlin, the build script does not recognize the sonatype block.

I have tried applying the Nexus Publish plugin, but to no avail. I have also tried looking through the documentation, but both the JReleaser and Maven Central docs reference each other.

// root-publication.gradle.kts (in buildSrc/src/main/kotlin)

plugins {
    `maven-publish`
    id("org.jreleaser")
}

allprojects {
    group = "io.github.aeckar"
    version = "1.0.0"
}

jreleaser {
    deploy {
        maven {
            mavenCentral {
                sonatype {    // Unresolved reference: sonatype
                    setActive("ALWAYS")
                    url = "https://central.sonatype.com/api/v1/publisher"
                    stagingRepository("target/staging-deploy")
                }
            }
        }
    }
}

Solution

  • Groovy DSL uses a different approach to create objects inside NameDomainObjectContainers. Since you are using Kotlin DSL, you will need to use the create("<name>") method instead. So instead of:

    sonatype {    // Unresolved reference: sonatype
        setActive("ALWAYS")
        url = "https://central.sonatype.com/api/v1/publisher"
        stagingRepository("target/staging-deploy")
    }
    

    You can use:

    create("sonatype") {
        setActive("ALWAYS")
        url = "https://central.sonatype.com/api/v1/publisher"
        stagingRepository("target/staging-deploy")
    }