使用 Maven 程序集插件排除依赖关系
我有一个装配项目,有两个直接依赖项,一个 war 和一个 jar。在程序集描述符中,我尝试将 war 放在一个文件夹中,将 jar 放在另一个文件夹中。因此,我使用以下 dependencySet 片段:
<dependencySets>
<dependencySet>
<outputDirectory>webapps</outputDirectory>
<includes>
<include>*:war</include>
</includes>
<directoryMode>750</directoryMode>
<fileMode>660</fileMode>
</dependencySet>
<dependencySet>
<outputDirectory>bin</outputDirectory>
<includes>
<include>mygroup:my-jar-artifact</include>
</includes>
<directoryMode>750</directoryMode>
<fileMode>660</fileMode>
</dependencySet>
</dependencySets>
但是,当我执行“mvn assembly:single”时,它总是最终将 jar 放置在 webapps 目录中。我已经尝试了一切可能的方法来强制它排除 jar (包括添加排除标签等)。我知道我可以通过使用 Maven 依赖插件将 jar 复制到文件夹,然后使用程序集描述符复制平面文件来解决此问题。但是,我真的觉得我应该能够使用依赖项集来做到这一点。有什么想法吗?
附加信息:
- 我使用的是 Maven 3.0.2,但 Maven 3.0.3 表现出相同的行为。
- 我对 jar 的 pom 依赖项使用“jar-with-dependencies”分类器。
I have an assembly project with two direct dependencies, a war and an jar. In the assembly descriptor, I am trying to place the war in one folder and the jar in another. As such, I am using the following dependencySet snippet:
<dependencySets>
<dependencySet>
<outputDirectory>webapps</outputDirectory>
<includes>
<include>*:war</include>
</includes>
<directoryMode>750</directoryMode>
<fileMode>660</fileMode>
</dependencySet>
<dependencySet>
<outputDirectory>bin</outputDirectory>
<includes>
<include>mygroup:my-jar-artifact</include>
</includes>
<directoryMode>750</directoryMode>
<fileMode>660</fileMode>
</dependencySet>
</dependencySets>
However, when I execute "mvn assembly:single", it always ends up placing the jar in the webapps directory. I have tried every possible way to force it to exclude the jar (including adding excludes tags, etc). I know I could do a workaround by using the by using the maven dependency plugin to copy the jar to a folder and then use the assembly descriptor to copy the flat file over. However, I really feel like I ought to be able to use dependency sets to do this. Any ideas?
Additional information:
- I am using maven 3.0.2 but maven 3.0.3 exhibits the same behavior.
- My pom dependency for the jar uses a 'jar-with-dependencies' classifier.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
难道它正在复制 WAR 的传递依赖关系吗?
尝试
使用或
在 WAR 的 dependencySet 中
。 程序集描述符文档
如果
useTransitiveDependencies
是关闭(默认情况下处于打开状态),则不应复制 WAR 的传递依赖项。如果 useTransitiveFiltering 打开(默认情况下关闭),您定义的过滤器将应用于 WAR 的传递依赖项,并且由于这包括
*:war
应该复制时不包含任何依赖 JAR。Could it be that it is copying transitive dependencies of the WAR?
Try using either
or
in the dependencySet of the WAR.
Assembly Descriptor documentation
If
useTransitiveDependencies
is turned off (it is on by default), the transitive dependencies of the WAR should not be copied.If
useTransitiveFiltering
is turned on (it is off by default), the filters you define will apply to the transitive dependencies of the WAR, and since this is including*:war
should not include any of the dependency JARs when copying.另一种可能性是语法
*:war
不正确。您能否尝试在
中显式指定 groupId:artifactId,就像您对jar
工件所做的那样?Another possibility is the syntax
*:war
is incorrect.Can you try specifying the groupId:artifactId explicitly in the
<include>
, the same way that you have done for thejar
artifact?我想通了。我打算查看程序集插件的源代码来找出问题所在。这样做时,我注意到我使用的是程序集 2.2-beta-1。升级到 2.2 完全解决了这个问题。吸取的教训是我下次应该检查插件的版本。
I figured it out. I was going to look at the source code for the assembly plugin to figure out the problem. In doing so, I noticed that I was using assembly 2.2-beta-1. Upgrading to 2.2 fixed the issue entirely. Lesson learned that I should always check the version of the plugin next time.