Unable to publish artifact to mavenCentral

I’m trying to upload one of my libraries to mavenCentral, but I’m stuck on the upload step.

I’ve taken example from this link: https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:complete_example, I only changed this line: artifactId = archivesBaseName and setting the repositories as following:

repositories {
        maven {
            def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
            def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl

            credentials {
                username ossrhUsername
                password ossrhPassword

The version is set to 1.0-SNAPSHOT

When running publish though I get the following output:

Version: 1.0-SNAPSHOT
> Task :jar:compileJava UP-TO-DATE
> Task :jar:processResources NO-SOURCE
> Task :jar:classes UP-TO-DATE
> Task :jar:jar UP-TO-DATE
> Task :jar:generateMetadataFileForMavenJavaPublication
> Task :jar:generatePomFileForMavenJavaPublication
> Task :jar:javadoc UP-TO-DATE
> Task :jar:javadocJar UP-TO-DATE
> Task :jar:sourcesJar UP-TO-DATE
> Task :jar:signMavenJavaPublication FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jar:signMavenJavaPublication'.
> Signing Gradle Module Metadata is not supported for snapshot dependencies.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':jar:signMavenJavaPublication'.
// more of the stacktrace

After some further research I’ve found a (supposed) solution, to change signing as following:

signing {
    required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
    sign publishing.publications.mavenJava

But this still keeps showing the same error. If I remove the signing block then the publish task succeeds, however I’m met with another problem; my artifacts appear in the search tab on sonatype, but not in “staging repositories”, which is empty. I’m guessing it’s the signing, but I am not sure how to confirm/deny this.

How can I resolve this issue?

I’m using Java 13, with Gradle 6.0-rc-1.

I have the same problem, using Java 13 with Gradle 6.0. Any solution to this?

I simply disabled Gradle Module Metadata: https://docs.gradle.org/current/userguide/publishing_gradle_module_metadata.html#sub:disabling-gmm-publication

I assume SonaType not yet supports the GMM.

Just tried it, it seems to be working for me.

This has nothing to do with SonaType, it is Gradle itself which does not support it currently.

required = false just means, that it is not required as the name of the flag suggests, not that it is not done, it only becomes optional.
If the necessary properties are set, the signing is done but if not, it does not fail.
If required is true and the properties are not set, the build will fail.

By wrapping the sign call in an if (required), you can make it only sign if required, no matter whether the properties are set or not.

With Gradle 6.2 the signing of snapshot releases should work again.
For further information see https://github.com/gradle/gradle/pull/11906 and https://github.com/gradle/gradle/issues/12070