Tuesday, July 8, 2014

Beware of -Dfile option when using mvn in Cygwin

Cygwin is my favorite tool that could allow me to execute Linux command on Windows. Sometimes I find it weird when I’m navigating to the root path of each partition where primary partition on Windows, which C:, were prefix with /cygdrive. At first I’m not so comfort with this approach but then later I started to adopt this culture in my daily routine job.

Here come to a problem when I was using Maven to install a third party dependency into my local Maven repository. When the following command was fired:

mvn install:install-file -Dfile=/cygdrive/c/Users/kok.hoe.loh/workspace/ProjectA/lib/AuditUtil.jar -DgroupId=org.huahsin.eai -DartifactId=AuditUtil -Dversion=0.0.1 -Dpackaging=jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ProjectA 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ ProjectA ---
[INFO] Installing C:\cygdrive\c\Users\kok.hoe.loh\workspace\ProjectA\lib\AuditUtil.jar to C:\Users\kok.hoe.loh\.m2\repository\org\huahsin\eai\AuditUtil\0.0.1\AuditUtil-0.0.1.jar
[INFO] Installing C:\Users\kok.hoe.loh\tool\Cygwin\tmp\mvninstall6980818442128433518.pom to C:\Users\kok.hoe.loh\.m2\repository\org\huahsin\eai\AuditUtil\0.0.1\AuditUtil-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.764s
[INFO] Finished at: Tue Jul 08 18:00:24 SGT 2014
[INFO] Final Memory: 5M/76M
[INFO] ------------------------------------------------------------------------
The build was success but the dependency was not install in my local Maven repository. There trace information has already show me the problem but I have overlook it. Notice that the dependency was install to C:\cygdrive\c\..., which is not what I want. It seems to me -Dfile option doesn't recognize Cygwin file system.

This fix was easy, just ignore the root when dealing with -Dfile, which is /cygdrive/c for my case. Following sample shows the real work.

mvn install:install-file -Dfile=/Users/kok.hoe.loh/workspace/ProjectA/lib/AuditUtil.jar -DgroupId=org.huahsin.eai -DartifactId=AuditUtil -Dversion=0.0.1 -Dpackaging=jar

No comments: