使用 maven tycho 使用由 maven-dependency-plugin 下载的清单条目 Bundle-ClassPath 进行构建
我有一个带有以下清单的 Eclipse 插件:
...
Bundle-ClassPath: .,
lib/drools-api.jar,
lib/drools-core.jar,
...
现在我们不想将 drools-api.jar
和 drools-core.jar
放入源代码管理中,因此我们使用插件从 Maven 存储库获取它们:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-bundle-classpath-libs</id>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<stripVersion>true</stripVersion>
<artifactItems>
<artifactItem>
<groupId>org.drools</groupId>
<artifactId>drools-api</artifactId>
</artifactItem>
<artifactItem>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
</artifactItem>
...
但是,第一次我们构建这个模块,它失败了,因为发生了这种情况:
[WARNING] Missing classpath entry lib/drools-api.jar ...
[WARNING] Missing classpath entry lib/drools-core.jar ...
...
[INFO] --- maven-dependency-plugin:2.1:copy (copy-bundle-classpath-libs) ... ---
...
[INFO] Copying drools-api-5.2.0-SNAPSHOT.jar to .../lib/drools-api.jar
[INFO] Copying drools-core-5.2.0-SNAPSHOT.jar to .../lib/drools-core.jar
...
[INFO] --- maven-osgi-compiler-plugin:0.10.0:compile (default-compile) ... ---
...
[INFO] Compiling 458 source files to ...
// ERROR because drools-api is not in the compilation classpath
如果我们再次构建它,它就会成功,因为 jars 已经在构建开始之前的 lib
目录:没有警告,并且 jar 位于编译类路径中。
我们如何解决这个问题,这样我们就不需要在源代码管理中提交 jar 并仍然使用 Bundle-ClassPath
?
注意:插件的当前实现要求我们使用 Bundle-ClassPath
:使用 Require-Bundle
不是一个选项。
I have an eclipse plugin with this manifest:
...
Bundle-ClassPath: .,
lib/drools-api.jar,
lib/drools-core.jar,
...
Now we don't want to put drools-api.jar
and drools-core.jar
in source control, so we use a plugin to fetch them from the maven repository:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-bundle-classpath-libs</id>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<stripVersion>true</stripVersion>
<artifactItems>
<artifactItem>
<groupId>org.drools</groupId>
<artifactId>drools-api</artifactId>
</artifactItem>
<artifactItem>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
</artifactItem>
...
However, the first time we build this module, it fails, because this happens:
[WARNING] Missing classpath entry lib/drools-api.jar ...
[WARNING] Missing classpath entry lib/drools-core.jar ...
...
[INFO] --- maven-dependency-plugin:2.1:copy (copy-bundle-classpath-libs) ... ---
...
[INFO] Copying drools-api-5.2.0-SNAPSHOT.jar to .../lib/drools-api.jar
[INFO] Copying drools-core-5.2.0-SNAPSHOT.jar to .../lib/drools-core.jar
...
[INFO] --- maven-osgi-compiler-plugin:0.10.0:compile (default-compile) ... ---
...
[INFO] Compiling 458 source files to ...
// ERROR because drools-api is not in the compilation classpath
If we just build it again, it succeeds, because the jars are already in the lib
directory before the builds starts: there are no warnings and the jars are in the compilation classpath.
How can we fix this so we don't need to commit the jars in source control and still use Bundle-ClassPath
?
Note: the current implementation of the plugin requires us to use Bundle-ClassPath
: using Require-Bundle
instead is not an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个已知的错误。
请参阅https://issues.sonatype.org/browse/TYCHO-577
this is a known bug.
see https://issues.sonatype.org/browse/TYCHO-577
我尝试过做类似的事情,但我的印象是这行不通。
似乎 maven-dependency-plugin 需要解析编译类路径才能下载 JAR(即使您通过指定依赖项)。
因此,第谷驱动的类路径解析在下载 JAR 之前执行,因此它们不会进入类路径。有点像先有鸡还是先有蛋的问题。
为了解决这个问题,我创建了一个单独的配置文件“download-deps”,用于刷新库目录(例如:
mvn -Pdownload-deps validate
)。不过,这个方法效果不佳,因为如果存在捆绑包
B
导入捆绑包A
提供的包,而捆绑包A
又嵌入包含该包的 JAR,则 B 的编译将会因未解决的依赖关系而失败。因此,您必须运行此命令,直到下载所有 JAR。非常难看。I have tried to do similar thing and I have got an impression that this will not work.
Seems like maven-dependency-plugin requires compile classpath to be resolved in order to download JARs (even when you specify dependencies via <artifactItems>).
As a result, Tycho-driven classpath resolution is executed before JARs are downloaded, so they do not make their way into the classpath. Kind of chicken and egg issue.
To solve that issue, I have created a separate profile "download-deps" which I used to refresh libraries directory (like:
mvn -Pdownload-deps validate
).This approcha does not work well, though, since if there are bundle
B
that import package provided by bundleA
, which in turn embeds JARs that contains that package, compilation of B will fail with unresolved dependency. Therefore, you have to run this command until all JARs are downloaded. Very ugly.