问题
In the past, we had our bundles and features on the file system and made them available in Eclipse through a target definition file with a 'Directory' location. In this way, it was easy to use them with the Export wizards in Eclipse.
Now I'm trying to build an eclipse-plugin
with Tycho which has third party dependencies, e.g. javax.vecmath and org.apache.commons.math.
From what I know, the best way to obtain the dependencies in a Tycho build is through a p2 repository. So I'm using one for the Eclipse bundles. But for my third-party bundles, it seems that there is no p2 repository available.
So my question is: How do I easily get the JARs (vecmath, commons-math) into a p2 repository?
I thought I could build a p2 repository with Tycho, but how to do this when I can't access the third-party bundles in Tycho? I tried to use a target definition, but Tycho only supports links to p2 repositories, and not directories or installations. So are there other ways to use my third-party dependencies in a Maven/Tycho build?
回答1:
According to your question, the third party dependencies are already bundles. This is good – all that is left to do is to generate p2 metadata for the bundles.
This can be done easily through the Features and Bundles Publisher application. The result is a p2 repository. Obviously, you don't want that all your developers have to do this locally in order to run the Tycho build, so you should put the result of the publisher application onto a web server. Then, reference the bundles via an http URL in the target file of your project.
回答2:
A few different options...
P2 plugin
Use p2-maven-plugin to wrap all your non-OSGi dependencies into bundles, and create a p2 repository.
I haven't tried p2-maven-plugin (it didn't exist when I was setting up my current project). Its implementation is based on tycho, but you may find it provides a more convenient way to solve your problem than just the tycho plugins on their own.
Bundle plugin
Use maven-bundle-plugin to wrap your non-OSGi dependencies (one wrapper pom per dependency), and install it into your repository. I think commons-math is already a dependency, so you might just need to wrap vecmath. You could then list those dependencies in the <dependencies>
of your tycho-based pom files.
This approach has the advantage that you don't need to set up a p2 repository just to build your project. The disadvantage is that managing dependencies in your bundle projects is no longer a case of just modifying the MANIFEST.MF file: you might also need to update the pom too.
Bundle plugin and Tycho
If you use the Bundle plugin approach to wrapping your dependencies into OSGi bundles, it may still be useful to set up a p2 repository for those dependencies anyway, as this simplifies setting up the target platform in Eclipse PDE.
To do this, you can create a new tycho-based project to collect the dependencies into a p2 repository: that is, the dependencies that are already bundles, together with the wrapped versions of the non-OSGi dependencies. This way, the project that creates the p2 repository lists the wrapped dependencies in its pom, and your bundle projects can consume the p2 repository without listing any dependencies in their poms.
This is the approach I am using. Specifically, I am using an eclipse-feature
project to define a base feature which includes all the third-party dependencies. I also have the <deployableFeature>
configuration option on the packaging plugin set to true
, which will create a p2 repository in the target directory. This feature can be installed into my usual Eclipse instance, which makes it easy to use the current Eclipse platform as the target platform. It can also be used as a p2 repository that can be used elsewhere in the tycho build (i.e. by my code), or as a repository in an Eclipse .target
file.
The eclipse-feature
seemed to be the best packaging type in Tycho 0.13.0. There may be a more appropriate packaging type in more recent versions.
回答3:
a good place to look for 3rd party bundle jars in p2 repos is eclipse orbit
http://download.eclipse.org/tools/orbit/downloads/
commons.math is in there.
If your 3rd party OSGi bundle is not available in a p2 repo, but in a maven repo such as
http://search.maven.org/
you may use tycho's pomDependency=consider switch:
http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts
回答4:
Here is an actual example how you can do this: https://github.com/skosmalla/generate-p2-repository-from-maven-artifacts
来源:https://stackoverflow.com/questions/13268213/how-to-use-directory-containing-third-party-bundles-in-a-tycho-build