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