Home > Mobile >  Gradle task: signMavenJavaPublication failed because it has no configured signatory
Gradle task: signMavenJavaPublication failed because it has no configured signatory

Time:05-29

I am trying to publish a Java library to maven central repository. I have never done this before. This project is for testing purposes. When I figure out how to properly publish a project, I will then publish an actual library. My goal is to be able to add this project as a dependency for other projects. I know I could include it as a .jar, but I want to learn about other ways of importing dependencies.

While running the task:

./gradlew publish

in my project root folder, I get the build error:

> Task :signMavenJavaPublication FAILED
Caching disabled for task ':signMavenJavaPublication' because:
  Build cache is disabled
Task ':signMavenJavaPublication' is not up-to-date because:
  Task has failed previously.
:signMavenJavaPublication (Thread[Execution worker for ':',5,main]) completed. Took 0.004 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':signMavenJavaPublication'.
> Cannot perform signing task ':signMavenJavaPublication' because it has no configured signatory

For the past two days, I have been trying to figure out why. I will post the build code further below, but first I will go through all the steps I followed to be able to publish to the central repository in the first place.

My gradle experience is limited, but I think I know the basics.

I have read various documentation on:

Structure

  1. And now we can get to the gradle files. Keep in mind, I'm not entirely sure if this is correct. If I left out something, or something is unnecessary. Please let me know.

build.gradle

plugins {
    id 'java-library'
    id 'signing'
    id 'maven-publish'
}

group 'io.github.username'
version '0.0.1'

repositories {
    mavenCentral()
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

dependencies {}

java {
    withJavadocJar()
    withSourcesJar()
}


publishing {
    publications {
        mavenJava(MavenPublication) {

            groupId = 'io.github.username'
            artifactId = 'storage'
            version = '0.0.1'
            from components.java

            pom {
                name = 'Storage'
                description = 'Storage is an open-source Java library test'
                url = 'https://github.com/username/Storage'
                inceptionYear = '2022'

                licenses {
                    license {
                        name = 'MIT License'
                        url = 'http://www.opensource.org/licenses/mit-license.php'
                    }
                }
                developers {
                    developer {
                        id = 'sonatype-username'
                        name = 'Full Name'
                        email = '[email protected]'
                    }
                }
                scm {
                    connection = 'scm:git:git://github.com/username/Storage.git'
                    developerConnection = 'scm:git:ssh://github.com/username/Storage.git'
                    url = 'https://github.com/username/Storage'
                }
            }
        }
    }
    repositories {
        maven {
            name = "OSSRH"
            url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
            credentials {
                username = project.properties["ossrhUsername"]
                password = project.properties["ossrhPassword"]
            }
        }
    }
}

signing {
    sign publishing.publications.mavenJava
}

javadoc {
    if(JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html5', true)
    }
}

gradle-wrapper.properties

# auto-generated
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

# Sonatype variables
ossrhUsername=username
ossrhPassword=password

# GnuPG
signing.keyId=********
singing.password=GnpPassword
signing.secretKeyRingFile=\Users\username\secring.gpg

settings.gradle

rootProject.name = 'Storage'

That should be it. But I can include versions of various software/tools:

  • OS Windows 10
  • GnuPG 2.3.6
  • Gradle 7.4.2
  • Java 13.0.1
  • Groovy 3.0.9

CodePudding user response:

The error piece:


> Cannot perform signing task ':signMavenJavaPublication' because it has no configured signatory

basically says that your signing task is not able to figure out the signature info it needs to execute. Most likely it cannot find your gradle-wrapper.properties file. What you can do is to try to put them in the main gradle.properties file and see how it goes.

As for the folders: Gradle relies on java.io.File for its path related operations which means it should be able to handle forward slashes as well.

A good approach, especially when you are setting up a new configuration and you see it failing for path reasons, is to put everything straight into the folder where you're sure Gradle (or any other system/build) is able to see it. In your case that would be either gradle home or same folder where your build.gradle is. Then, after you get everything to work, you can reorganize and put configs however you like.

EDIT:

It is also always a good idea to find a way how to printout something while your build / script / whatever is executing. So, for Gradle you can use println to print a property name:

task printSigning {
    println(project.findProperty('signing').secretKeyRingFile)
}

Or you can print a current directory:

task currentDir {
    println file('.')
}

I hope that this helps a bit.

Below questions might contain some more details and give you a hint too:

https://stackoverflow.com/a/67115705/177154

https://stackoverflow.com/a/68505768/177154

CodePudding user response:

I figured out what was wrong. I found out that my gradle home directory was located under C:\Gradle\gradle-7.4.2. Thought it was under C:\Users\username\.gradle. So i made a new gradle.properties under that location with the all the passwords and key info from my projects gradle.properties. I don't know why the project property file wouldn't be enough. I would rather have the credentials stored in my project.. But at least i figured out what was wrong and got to publish it. If someone sees this and have some ideas let me know.

  • Related