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 an unpack
goal to maven-dependency-plugin
during the initialize
phase. This unpacks the artifacts that I specify to a separate target/dependencies
directory.
The target/dependencies
directory is added as an output directory in build.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 the Bundle-ClassPath
library in META-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 use unpack-dependencies
instead of unpack
, 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 the target/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 run mvn 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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…