I\'d like to use dependencies from a remote Eclipse p2 repository in a \"regular\" Maven 3 build (e.g. JAR or WAR packaging) - all without converting the p2 repo to a local
Looks like I'm answering another of my own questions..
First of all, you can use Tycho to add a dependency on a bundle from a P2 repository:
Let's give that a try:
$ mvn dependency:tree
[INFO] com.example:org.eclipse.xsd:eclipse-plugin:0.0.1
[INFO] +- p2.eclipse-plugin:org.eclipse.xsd:jar:2.6.0.v20100914-1218:system
[INFO] ...
[INFO] \- p2.eclipse-plugin:org.eclipse.core.filesystem:jar:1.3.1.R36x_v20100727-0745:system
Our dependency has sucessfully been resolved from the P2 repository. Unfortunately, we're not done yet. The dependency has been added with system scope, which means that the artifacts won't be included if we create a webapp that depends on our build. To work around that, we'll first unpack all classes contained in the dependency to some directory, and then re-package that directory as a jar and use it as the final artifact of our build.
For the first part (unpacking), we add the maven-dependency-plugin to our build and configure it to run its unpack-dependencies goal during the package phase. For the second part (re-packaging), we add the maven-assembly-plugin to our build and configure it to run its single goal during the package phase. We also need to create and configure a custom assembly descriptor.
Our build now consists of 3 files: The build file in pom.xml:
4.0.0
com.example
org.eclipse.xsd
0.0.1
eclipse-plugin
helios
p2
http://download.eclipse.org/releases/helios
org.eclipse.tycho
tycho-maven-plugin
0.12.0
true
org.apache.maven.plugins
maven-dependency-plugin
unpack-dependencies
package
unpack-dependencies
${project.build.directory}/dependency
false
true
org.apache.maven.plugins
maven-assembly-plugin
2.2.1
src/main/assembly/repackaged.xml
make-assembly
package
single
The manifest in META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ignored
Bundle-SymbolicName: Ignored
Bundle-Version: 0.0.1
Require-Bundle: org.eclipse.xsd
Bundle-Vendor: Ignored
The assembly descriptor in src/main/assembly/repackaged.xml:
repackaged
jar
false
${project.build.directory}/dependency/
/
true
Now mvn package will create a jar file that contains all the code from our P2 dependency, re-packaged as a proper Maven artifact, ready to be used as a dependency in another project.
$ jar tf target/org.eclipse.xsd-0.0.1-repackaged.jar
org/eclipse/xsd/ecore/XSDEcoreBuilder$1.class
org/eclipse/xsd/ecore/XSDEcoreBuilder$2.class
org/eclipse/xsd/ecore/XSDEcoreBuilder$Comparator.class
org/eclipse/xsd/ecore/XSDEcoreBuilder$EffectiveOccurrence.class
org/eclipse/xsd/ecore/XSDEcoreBuilder.class