I have a bunch of Eclipse-based plugins that I have been migrating to Maven/Tycho. Most of these plugins depend on separate libraries that I now manage through Maven, rather than muddle around with .jar
files.
The most cumbersome part of my current setup is due to the apparent inability of Tycho to process Maven-only (i.e. non-OSGi) artifacts. My current setup works like this:
In the
pom.xml
of each Eclipse plugin I issue anunpack
goal tomaven-dependency-plugin
during theinitialize
phase. This unpacks the artifacts that I specify to a separatetarget/dependencies
directory.The
target/dependencies
directory is added as an output directory inbuild.properties
, so that Tycho can add it to the classpath when compiling:source.. = src/main/java/ output.. = target/classes/ output.. = target/dependencies/
The
target/dependencies
directory is added to theBundle-ClassPath
library inMETA-INF/MANIFEST.MF
.
These settings allow the compile
Maven directive to compile the plugin. Importing the project from VCS and manually specifying the target/dependencies
directory as a class folder in Eclipse allows said IDE to also compile the plugin.
Unfortunately this is a rather cumbersome solution for a few reasons:
Configuring the
maven-dependency-plugin
requires listing all artifacts that should be unpacked. One could useunpack-dependencies
instead ofunpack
, but that would also unpack all OSGi dependencies - having half of Eclipse unpacked in each project directory is not my idea of fun...Adding the class folder in Eclipse requires Maven
initialize
to be run once, so that thetarget/dependencies
directory is created.There is no source connection between the pure Maven projects and their depending Tycho projects in Eclipse. For a change to propagate from a Maven project to an Tycho project, so that e.g. Eclipse may show a potential compilation problem, one has to
mvn install
the Maven project and then runmvn clean initialize
in the Tycho project to remove the previously unpacked dependencies and pull in the current set. Then you have to refresh the Eclipse project and hope that Eclipse does the right thing.In the same vein, viewing the source of a dependency from a Tycho project will not show the primary source file, but rather whatever is available in
target/dependencies
- quite possibly just a.class
file.
I am thinking that there must be a more reasonable way to go about this - something that would allow Eclipse and Maven projects to integrate more tightly.
So, what am I missing? What is the recommended setup for this use case? Is there a better alternative? Preferably something that would not require setting a bunch of Nexus and/or p2 repositories?
It seems like we apply similar strategies. However, I use a nexus mixed repository (having both maven and p2).
Maven plugin:
Example build.properties
Example manifest (only a subset of jars):
The official demo indeed works well and shows the way to embed non-OSGI dependencies, or in other words create OSGI facade for other dependencies.
The way is indeed copying the dependencies manually, making them part of OSGI manifest and exporting packages of interest.
The real problem is however the execution of the dependency plugin from within Eclipse.
Is simply doesn't run, even with respective M2E connector thus blocking discovery and PDE class-path resolution.
You can try maven-bundle-plugin with Embed-Dependency.
See http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts
The official demo works well. However, i'm still not succeed in using my jar file in this way.