Thursday, January 14, 2010

Bootstrap missing Maven project dependencies from source

From time to time one might face the problem that a required dependency for a Maven based project is not found in a public Maven repository, although it's source is accessible and it even turns out to be a maven based build. If you are fine with downloading the source, building and installing the needed artifacts into your local or company's repository, you are done quite easily. But what if you want to open your own project to a wider community, unable to share a common repository - how to produce a common, reproducible (kind of) and self-contained project build?

Here is where the bootstrap goal of the Maven scm plugin comes handy. It allows you to check out your dependency from source control and build and install it as a subtask of your own project build. If this is done before the main build's dependencies are resolved, you will get a nicely resolved self-contained build.


<dependencies>
<dependency>
<groupid>org.jboss.weld</groupid>
<artifactid>weld-se</artifactid>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
...
</dependencies>
<profiles>
<profile>
<id>bootstrap</id>
<build>
<plugins>
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-scm-plugin</artifactid>
<version>1.0</version>
<executions>
<execution>
<id>resolve-weld-se</id>
<phase>initialize</phase>
<goals>
<goal>bootstrap</goal>
</goals>
<configuration>
<goals>install</goals>
<connectionurl>scm:svn:http://anonsvn.jboss.org/repos/weld/java-se/trunk
</connectionurl>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

This is an example for resolving JBoss Weld SE, the standalone version of the Weld CDI / JSR299 dependency injection container for JEE6, which I needed to build the Struts 2 CDI plugin. Currently it is not found in a public maven repo, while the source is freely available. Declaring this as a needed dependency would result in Maven not being able to resolve it in against any known repository, finally notifying you that you have to install it manually in your local repository.

But if you now - at least for the first time - call your build with mvn -P bootstrap <goal> to run with activated "bootstrap" profile, the project you depend on will be checked out from source, built and finally installed in your local maven repository during the initialize phase of your own project's build - et voilĂ , your project will now (hopefully) compile with nicely resolved dependencies.


No comments:

Post a Comment

Labels

howto (4) java (3) appclient (2) ejb (2) glassfish (2) jee6 (2) maven (2) netbeans (2) scm (2) tutorial (2) adp1 (1) android (1) announcements (1) cdi (1) dependencymanagement (1) deployment (1) eclipse (1) extusb (1) fluff (1) g1 (1) git (1) htc (1) jee (1) jsr299 (1) liferay (1) m2eclipse (1) miniusb (1) operations (1) plug (1) portlet (1) servlet (1) struts2 (1) svn (1) tomcat (1) windows (1)