I'm trying to get my first Gradle project uploaded to Maven Central. I've followed Sonatype's documentation for this and have created an uploadArchives
task for generating the metadata.
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
...etc. etc.
The task references two properties, "ossrhUsername" and "ossrhPassword", which I'm supposed to define in gradle.properties
; however, if I do not have a gradle.properties
with these properties, the build fails with an error, even for non-uploadArchives
tasks.
$ gradlew test
Could not get unknown property 'ossrhUsername' for object of type org.gradle.api.publication.maven.internal.deployer.DefaultGroovyMavenDeployer.
I would like for the build to succeed (apart from the uploadArchives
task, of course) without having to define these properties in a gradle.properties
file.
How do I go about doing this?
Would it be simpler to just manage a separate pom.xml
exclusively for Maven Central uploading?
EDIT The identified potential duplicate is about where to externalize credentials. My question is how to ensure the Gradle build still executes successfully despite the credentials not being externalized in gradle.properties
. I would like for others to be able to clone the repo and execute Gradle without having to define OSSRH credential properties.
Instead of referencing the property directly, I passed the property name as a String to findProperty
, which eliminated the error. The API documentation indicates this method is "Incubating", but it's been around since version 2.13.
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword'))
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword'))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With