在整合Maven,Tycho和Eclipse时处理非OSGi依赖关系 [英] Handling non-OSGi dependencies when integrating Maven, Tycho and Eclipse
问题描述
.jar
文件。 当前设置中最麻烦的部分是由于Tycho无法处理Maven-only(即非OSGi)工件。我目前的设置是这样的:
-
在
pom.xml
每个Eclipse插件我在初始化期间发行
阶段。这将我指定的工件解包到一个单独的解压缩
目标到maven-dependency-plugin
target / dependencies
目录。 -
target / dependencies
目录作为build.properties
中的输出目录添加,以便Tycho可以在编译时将其添加到类路径中:source .. = src / main / java /
output .. = target / classes /
输出.. =目标/依赖/
-
target / dependencies
目录添加到META-INF / MANIFEST.MF
中的Bundle-ClassPath
这些设置允许编译 Maven指令来编译插件。从VCS导入项目,并在Eclipse中手动指定 target / dependencies
目录作为类文件夹,允许IDE还编译插件。
不幸的是,这是一个相当麻烦的解决方案,原因如下:
-
配置
maven-dependency-plugin
需要列出应该解压缩的所有工件。一个可以使用unpack-dependencies
而不是unpack
,但这也会解压所有OSGi依赖关系 - 在每个项目目录中解压缩一半的Eclipse不是我的想法... -
在Eclipse中添加类文件夹需要Maven
initialize
要运行一次,以便创建target / dependencies
目录。
纯粹的Maven项目与Eclipse中依赖的Tycho项目之间没有源连接。对于从Maven项目传播到Tycho项目的更改, Eclipse可能会显示一个潜在的编译问题,一个必须是在$ m code $ mvn install Maven项目中,然后运行
mvn clean initialize
Tycho项目删除以前解包的依赖关系并拉入当前集。那么你必须刷新Eclipse项目,并希望Eclipse做正确的事情。 同样,从Tycho项目中查看依赖关系的来源将>不显示主源文件,而是 target / dependencies
中可用的任何内容 - 很可能只是一个 .class
文件。
我认为必须有一个更合理的方法来解决这个问题这将允许Eclipse和Maven项目更紧密地集成。
那么,我还缺少什么?该用例的建议设置是什么?有更好的选择吗?最好是不需要设置一堆Nexus和/或p2存储库的东西?
似乎我们应用了类似的策略。但是,我使用了一个nexus混合的存储库(具有maven和p2)。
- 对于解包依赖关系,我使用maven依赖插件将它们放在目标/依赖中(见下文)。
- 1.1。复制依赖关系在没有解压缩的情况下执行所需的操作。
- 您的源和输出与我的大致相同。
- 2.1。是的,mvn必须初始化目标/依赖关系
- 我只在MANIFEST中包含所需的jar,因为1将检索许多不必要的jar 。
- 3.1。我手动选择相关的罐子。
- 3.2。是的,如果非Eclipse管理的(maven)项目更改(在您的工作空间之外),那么您必须运行mvn构建来更新它们。
- 3.3。实现此功能的关键是:
- 3.3.1 将您的maven和Eclipse项目部署到(快照)存储库。我使用 http://www.sonatype.org/nexus/ 。因此,当您运行maven时,它会查看nexus存储库以更新maven和Eclipse项目。
- 其他一些注释可能已经很明显:
- 4.1。 pom.xml文件应该只包含非Eclipse jar作为依赖关系。 (tycho插件处理所有的Eclipse依赖项,应该在你的(nexus)存储库中找到。)
- 4.2。在Eclipse中将依赖的jar添加到运行时(通过编辑plugin.xml运行时)
Maven插件:
< plugin>
<! - 将非Ecipse插件复制到目标/依赖关系,以便可以引用
来运行时使用。 - >
< artifactId> maven-dependency-plugin< / artifactId>
< version> 2.1< / version>
<执行>
< execution>
< id> copy-dependencies< / id>
< goals>
< goal> copy-dependencies< / goal>
< / goals>
< configuration>
< excludeGroupIds> org.XXX< / excludeGroupIds>
< / configuration>
< / execution>
< execution>
< id> classpath< / id>
< goals>
< goal> build-classpath< / goal>
< / goals>
< configuration>
< fileSeparator> /< / fileSeparator>
< prefix> target / dependency< / prefix>
< outputFile> $ {project.build.directory} /classPath.txt
< / outputFile>
< / configuration>
< / execution>
< / executions>
< / plugin>
示例build.properties
bin.includes = META-INF /,
target / classes /,
plugin.xml,
target / dependency / mongo-java-driver-2.11.3 .jar
示例清单(只有jar的一个子集):
Bundle-ClassPath:。,
target / classes /,
target / dependency / mongo-java-driver-2.11.3.jar
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).
- For unpacking dependencies, I use the maven-dependency-plugin to place them in target/dependency (see below).
- 1.1. copy-dependencies does what is needed without unpack.
- Your source and output is about the same as mine.
- 2.1. Yes, mvn has to initialize the target/dependencies
- I only include the required jars in the MANIFEST, because 1 will retrieve many unnecessary jars.
- 3.1. I manually select the relevant jars.
- 3.2. Yes, if the non-Eclipse-managed (maven) projects change (outside of your workspace), then you have to run mvn build to update them.
- 3.3. A key to making this work, is to:
- 3.3.1 Deploy your maven and Eclipse projects to a (snapshot) repository. I use http://www.sonatype.org/nexus/ . Thus, when you run maven, it looks at the nexus repository for updates of both maven and Eclipse projects.
- Some other notes, which may already be obvious:
- 4.1. The pom.xml file should only contain non-Eclipse jars as dependencies. (The tycho plugin handles all the Eclipse dependencies, which should be found in your (nexus) repository.)
- 4.2. Add the dependent jars to the runtime in Eclipse (by editing the plugin.xml runtime)
Maven plugin:
<plugin>
<!-- Copy non-Ecipse plugins to target/dependency so that may be referenced
for runtime use. -->
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<excludeGroupIds>org.XXX</excludeGroupIds>
</configuration>
</execution>
<execution>
<id>classpath</id>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<fileSeparator>/</fileSeparator>
<prefix>target/dependency</prefix>
<outputFile>${project.build.directory}/classPath.txt
</outputFile>
</configuration>
</execution>
</executions>
</plugin>
Example build.properties
bin.includes = META-INF/,
target/classes/,
plugin.xml,
target/dependency/mongo-java-driver-2.11.3.jar
Example manifest (only a subset of jars):
Bundle-ClassPath: .,
target/classes/,
target/dependency/mongo-java-driver-2.11.3.jar
这篇关于在整合Maven,Tycho和Eclipse时处理非OSGi依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!