Sunday, June 23, 2013

Maven2: Creating run time maven repository for external jar dependencies.

Recently I came across a situation where I had to consume a third party project on the nightly basis. Provisioning and deploying a maven repository management tool for just one of the jar files is not what I felt worth investing time and hardware resources.

We asked third party vendor to keep pushing the required jar file to a stage location available to our build system. Added an extra maven module which serves the following purpose:

  • Location named lib which holds the required jar file.
  • Ant build.xml file which does “maven deploy:file” to the same location at the module level.
Module structure
|-- build.xml
|-- pom.xml
<exec executable="mvn">
  <arg line="-B deploy:deploy-file -Dfile=${basedir}/lib/&lt;required jar file>.jar -DgroupId=com.example.product -DartifactId=jarname  -Dversion=jarversion  -Dpackaging=jar -Durl=file://repo -DcreateChecksum=true"/>

     <ant target="default"/>

  •  Above 2 steps will create in project maven repository at the module build stage.
To consume the dependencies added to the in module repository we need to modify the parent pom to add the repository at the repositories section as:
            <name>stage repo</name>
and add the stage to the <modules> section in parent pom.

Further we are ready to consume the dependency “com.example.product:jarname” to any maven module after the stage module. 

Footnote: the above magic fails to work in Maven3. I think Maven3 tries to gather and resolve all the project modules dependency at the start of the maven reactor. In the case above repository is created at build time during the call of the stage module.

cheers, make world open.

No comments: