Making maven release plugin on windows with git, gpg and github to work

 

If you already spent time looking for answers you may want to skip the background. The very quick answer is to use the following combination:

  • Official windows Git configured to use plink
  • plink.exe, puttygen.exe and pageant.exe from here
  • GnuPG for windows, the minimal installation would do
  • Standard windows command prompt, not git bash not cygwin shell

The long story

I recently tried to release “properly” an old open source project of mine at the sonatype open source maven repository mostly to learn how to do a complete maven managed project. The particular project was a good use case, a small multiple module project with two modules, one module the library and one a web demo (war packaging).

The  past two months I am using windows (linux user on gaming period!) and I found out that the combination of maven release plugin, git managed project, gnupg to sign the jars is almost like a catch 22 for windows users with errors about paths, invisible passphrase prompts and hangs. Also it is surprising how little information is out there and how none of the solutions solved the problem so I decided to write this small guide.

 

Background

Usual problems

The usual options you have when working on windows to do things with maven are:

  • Cygwin shell. My preferred one with the respective versions of tools(git, svn, ssh, gpg etc).
  • Git bash for working with git. A middle ground option.
  • Windows command prompt. Awful, but the only one with a full native environment.

Using cygwin or git bash generates errors related with the sub-modules paths (works fine in single module projects):

 error: pathspec '"tiles-dynamic-lib\\pom.xml"' did not match any file(s) known to git.

Using windows command prompt I had very hard trouble setting ssh agent, so the process was hanging when release plugin was trying to connect to the server.

Solution

The solution is go fully windows in this case and run tools from the putty family. So basically, you just need to set up putty pagent, gnupg for windows and then use the command prompt.

A working combination

  • Official windows Git configured to use plink
  • plink.exe, puttygen.exe and pageant.exe from here
  • GnuPG for windows, the minimal installation would do
  • Standard windows command prompt, not git bash not cygwin shell

Steps to setup

  • Install and add gnupg bin to your PATH (usually c:\Program Files\GNU\GnuPG\pub)
  • Install msys git, and choose to use plink. Also it is better to chose the less intrusive options for the path (only git). Check that c:\Program Files\Git\cmd is in your path and add it manually, if it is not
  • Put putty somewhere, e.g. c:\Program files\putty and optionally add it to your path
  • Use pyttygen.exe to convert your ssh key to the ppk (putty private key) format and save it under your home/.ssh folder (or whereever you save keys)
  • Use putty.exe to setup a connection to github. Set host in the front page, username in the Connection/Data and the key in the SSH/Auth.
    Connect to accept the server keys and test connection.
  • Start pagent.exe (goes to the system tray) and load your github key
  • Open a windows command prompt at your working copy and verify that things work:
    e.g. git push to test that you have write permissions
    You should not get asked for a passphrase, if you do then either git is not setup to use plink or putty connection is not correctly configured. Try connecting to github with putty and make sure you don’t get asked a passphrase

If all things work well, then at the windows command prompt try to prepare the release again (useful cheat-sheet dealing with release plugin):

# If you were left with a messy working copy from errors,
# you can reset to a fresh one from origin with the following
# Warning, it will erase all your local changes
> git reset --hard remotes/origin/HEAD

# Clean the failed release
> mvn release:clean

# Prepare the release again. This does:
# Everything should go well now
> mvn release:prepare

# Perform the release# Builds and dep
> mvn release:perform 

The above worked for me. I hope it helped

Leave a Reply