2

I'm using GnuPG to sign my jar before publishing to sonatype nexus central.

Here is the definition file:

subprojects {

    // https://stackoverflow.com/a/66352905/1772342

    val signingKeyId = providers.gradleProperty("signing.gnupg.keyId")
    val signingKeyPassphrase = providers.gradleProperty("signing.gnupg.passphrase")
    signing {
        useGpgCmd()
        if (signingKeyId.isPresent && signingKeyPassphrase.isPresent) {
            useInMemoryPgpKeys(signingKeyId.get(), signingKeyPassphrase.get())
            sign(extensions.getByType<PublishingExtension>().publications)
        } else {
            logger.info("PGP signing key not defined, skipping signing configuration")
        }
    }

When I run the following command:

gradlew publishToSonatype \
  closeSonatypeStagingRepository \
  -PsonatypeApiUser="..." \
  -PsonatypeApiKey="..." \
  -Psigning.gnupg.keyId="E1D4CD2CE69ED220" \
  -Psigning.gnupg.passphrase="..." \
  "${@}"

I got the following error:

> Task :core:signMavenPublication FAILED
:core:signMavenPublication (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core:signMavenPublication'.
> Error while evaluating property 'signatory' of task ':core:signMavenPublication'
   > Could not read PGP secret key

This error is very strange, as the PGP secret key can be easily fetched in my OS by the gpg command, yet gradle still complain not being able to find it

What should I do to make gradle doing the right thing?

The main project is visible here:

https://github.com/tek/splain/blob/7a2d3829516896337627f9b214ab0c8eb1f66aa3/build.gradle.kts

tribbloid
  • 4,026
  • 14
  • 64
  • 103

0 Answers0