如何使测试 jar 包含 Maven 中的依赖项?
我有一个具有 src/main/java 和 src/test/java 结构的项目,我设法使用 maven-jar-plugin 构建测试分支的 jar。但是,我想打包测试 jar,以便解决所有依赖项。有没有办法告诉 maven-jar-plugin 包含依赖项?
谢谢!
坦率
I have a project with src/main/java and src/test/java structure, and I managed to use maven-jar-plugin to build a jar of the test branch. However, I want to package the test jar so that all the dependencies are resolved. Is there a way I can tell maven-jar-plugin to include the dependencies??
Thanks!
Frank
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我在需要在 Hadoop 上运行的集成测试中遇到了类似的问题。我们的集成测试位于单独的集成测试模块的
test
文件夹中,因此需要一个test-jar-with-dependencies
来让我们的生活更轻松。我正在使用 Michael-O 提到的 程序集插件 。我的程序集描述符位于 src/main/ assembly/test-jar-with-dependency.xml 中,是标准
jar-with-dependencies
描述符是插件的一部分:这装配依赖于
test-jar
作为模块构建的一部分创建。因此,我将以下内容添加到模块的 pom.xml 中:I had a similar problem with integration tests I need to run on Hadoop. Our integration tests are located in the
test
folder of a separate integration test module, so what is required is atest-jar-with-dependencies
to make our life easier.I'm using the assembly plugin as mentioned by Michael-O. My assembly descriptor is located in
src/main/assembly/test-jar-with-dependencies.xml
and is a modification of the standardjar-with-dependencies
descriptor that's part of the plugin:This assembly relies on the
test-jar
being created as part of the module build. So I added the following to the module'spom.xml
:您可以这样做:使用 程序集插件 创建一个 jar 程序集,解压依赖项,打包一个新的测试 jar 并将其附加到反应器。你完成了。
打包的描述符可能类似于 this 。
You can do this: Create a jar assembly with the assembly plugin, have the dependencies unpacked, pack a new test jar and attach it to the reactor. You're done.
The descriptor for the packaging could look like this.
在类似的情况下,我最终将测试代码移动到一个单独的 jar 中,并使其依赖于原始代码。您可以使用聚合器项目来确保在构建主 jar 时运行测试。
In a similar situation I ended up moving my test code to a separate jar and made it depend on the original one. You can use an aggregator project to ensure that tests are run when you build the main jar.
要在程序集中包含测试 jar 依赖项,请指定程序集 debendencySet 的包含过滤器,如下所示:
to include a test-jar dependency in your assembly specify the include filter of the assembly debendencySet as bellow:
以下适用于 Maven 3
POM.XML
汇编文件
The following worked for Maven 3
POM.XML
ASSEMBLY FILE
我用它来包含测试 jar。重要的一行是
test-jar
。我不确定这是否是您所需要的。3年前,但可能对其他人有帮助。至少,它对我有帮助。 :-)
I use this to include the test jar.the important line is
<type>test-jar</type>
.I am not sure this is what you need.3 years ago, but may help others.At least, it helped me. :-)