Thursday, March 3, 2011

Maven Release and Directory Locations

A co-worker of mine ran into a strange error while running a maven release:prepare goal on a new project we were setting up, and the issue is kind of odd.

When he ran the prepare goal he would quickly get (on the first module) this error:
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] null
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NullPointerException
at org.apache.maven.shared.release.util.ReleaseUtil.getBaseWorkingDirect
oryParentCount(ReleaseUtil.java:233)
at org.apache.maven.shared.release.phase.RewritePomsForReleasePhase.tran
slateScm(RewritePomsForReleasePhase.java:109)
at org.apache.maven.shared.release.phase.RewritePomsForReleasePhase.tran
sformScm(RewritePomsForReleasePhase.java:62)

Google didn't really help much so I had a look at source for those classes and tried to figure out where the null was coming from. While I was looking around I remembered that he had checked out the project into his root directory, so the working directory was directly inside "C:\".

That is:
C:\project\pom.xml was the top level pom getting built.

Since the release plugin looks for some base and parent directories I wondered if this made a difference, if asking for the base directory and just getting "C:\" was an issue. I tried to run the same goal on my machine, with a more nested working directory and it finished successfully. We tried adding one level of directories between his root and his workspace (C:\blah\project\pom.xml) and that seemed to do the trick.

I've logged a bug report with the maven release plugin about this: http://jira.codehaus.org/browse/MRELEASE-663, but in the interm if anyone runs into it just make sure you aren't doing your dev too close to root.

Thanks,
Brent