Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple errors staging a release in Maven?

Tags:

maven

While trying to push a release to Maven, I am getting several errors including:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

and

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to commit files
Provider message:
The git-commit command failed.
Command output:
like image 855
Phyxx Avatar asked Mar 15 '26 00:03

Phyxx


1 Answers

So this is really just a brain dump of the process I had to go through to push a release for an open source project hosted on git into the Sonatype maven repo. Almost everything here has been covered in separate StackOverflow questions, but for those (like me) doing this for the first time, an overview is useful.

The whole process is actually just two commands:

  • mvn release:prepare
  • mvn release:perform

However, it's the fiddly details that caught me out. So this is the process I needed to follow:

  1. Check in all changes to your project. Maven will complain if there any any unpushed local changes.
  2. Make sure you have a SSH public key in git. This will fix or prevent the Permission denied (publickey). error.
  3. Make sure you project's version is a SNAPSHOT and delete the release.properties file if it exists. This will fix or prevent the The git-commit command failed. error.
  4. Run the Maven commands listed above.
  5. I added the GPG key details to ~/.m2/settings.xm. The complete file is listed below.
  6. At this point you will have unsigned artefacts waiting in the staging area. I was uploading a parent POM file only, so I needed to sign then with the command mvn -Pgpg gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=pom.xml -Dfile=pom.xml
  7. Now release it with the instructions at https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-8a.ReleaseIt

This is the ~/.m2/settings.xml file.

<settings>
    <servers>
        <server>
            <id>sonatype-nexus-snapshots</id>
            <username>username</username>
            <password>password</password>
        </server>
        <server>
            <id>sonatype-nexus-staging</id>
            <username>username</username>
            <password>password</password>
        </server>
    </servers>
    <profiles>
        <profile>
            <id>gpg</id>
            <properties>
                <gpg.passphrase>password</gpg.passphrase>
                <gpg.keyname>12345678</gpg.keyname>
            </properties>
        </profile>
    </profiles>
</settings>
like image 140
Phyxx Avatar answered Mar 17 '26 16:03

Phyxx