Cygwin and Maven Deploy
A few days ago I completed some work on the Facebook Java API open source project and I wanted to create a snapshot release with the new functionality. The Maven snapshot repository is hosted by a member of the project and it uses public/private keypair authentication. This is a fairly common setup for Maven repositories. Unfortunately, I couldn’t get the Maven deploy plugin to work.
My workstation is running Windows 7 with Cygwin, and from a Cygwin terminal I was able to ssh to the repository just fine so I knew the public/private keys were correct. However, whenever I ran the Maven deploy command, the private key wasn’t found and I was prompted for password authentication.
Maven repository authentication details are stored in a settings.xml file, that, under Cygwin, lives at ~/.m2/settings.xml. I modified this file to include a server entry for the repository and added a privateKey setting with the path set to ~/.ssh/id_dsa. Still the deploy command did not work.
The issue, it turns out, is the confusion between Cygwin, Windows and Maven. If you run the Maven command from Cygwin, your settings file will not be accessed at ~/.m2/settings.xml, and the private key path specified in that file will not be accessible. The settings.xml file is accesed at your Windows home directory when you run Maven, in my case this was “C:\Users\dabdinoor\.m2\settings.xml”. The solution is to copy both your ~/.ssh and ~/.m2 directories to a more Windows-friendly location and update the private key in settings.xml. Detailed instructions follow.
Make sure you have your private key stored in ~/.ssh/ then, at a Cygwin terminal, SSH to the machine hosting the repository:
ssh mrepo@mrepo.server.com
You will be prompted to approve the host computer, it’s signature will be added to your ~/.ssh/known_hosts file. If your private key is approved you should not be prompted for a password.
In Cygwin, copy the ~/.ssh directory to your Windows home directory, this is “C:\Users\dabdinoor” in my case. Also copy the ~/.m2 directory to your Windows home directory.
Next, edit your settings.xml file. Update the private key entry for the repository server:
<server>
...
<privateKey>C:/Users/dabdinoor/.ssh/id_dsa</privateKey>
...
</server>
mvn clean install deploy
Now Maven should be able to properly access the private key and it won’t prompt you to approve the host because it was found in the known_hosts file. Deploy should then be able to succesfully upload to your repository.
Since Maven runs as a Windows process (and not under Cygwin) it is going to look for both your .m2 and .ssh directories under your Windows home directory, not your Cygwin home directory.
I just ate a banana
Cheers - I was stuck getting maven working for JIRA development. It’s so nice to have the Cygwin environment available, but every now and then the cracks appear and you see that horrible Windows environment peeking through.
I copied my .m2 folder to D:\Documents and Settings\myname\ and then created a symlink in Cygwin to make it more transparent:
% ln -s /cygdrive/d/Documents\ and\ Settings/myname/.m2 .m2