如何配置 Maven Shade 插件以在我的 jar 中包含测试代码?
我使用 Shade maven 插件来构建我的项目,以便其所有依赖项都包含在一个 jar 中(这使得在 Hadoop 上运行它变得更容易)。 Shade 似乎默认排除了我的测试代码,这是可以理解的。由于我想针对我的集群运行集成测试,我希望设置另一个配置文件来为此目的构建一个单独的 jar。有什么方法可以配置此插件以包含测试代码吗?
I use the shade maven plugin to build my project so that all of its dependencies are included in one jar (this makes it easier to run it on Hadoop). Shade seems to exclude my test code by default, which is understandable. Since I would like to run integration tests against my cluster, I am hoping to setup another profile to build a separate jar for this purpose. Is there any way to configure this plugin to also include test code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最后几个答案充其量只是针对损坏的功能的混乱解决方法。事实仍然是
maven-shade-plugin
中存在一个错误。与此同时,我调查并找出了该错误的根源,并创建了一个补丁。现在,我希望 Apache 的某个人尽快将其纳入其中,最终shadeTestJar
功能可以像预期的那样工作。These last couple of answers are messy workarounds for a broken feature at best. The fact of the matter remains that there is a bug in
maven-shade-plugin
. In the meantime I've investigated and root-caused the bug, and created a patch. Now I hope someone at Apache includes it soon and then finally theshadeTestJar
feature can work like it's supposed to.在 maven-shade-plugin 2.2 版本中,他们添加了一个“shadeTestJar”选项(请参阅 MSHADE-158): http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#shadeTestJar
但是,我尝试使用这个,但无法无法让它发挥作用。这是我的插件配置:
“...-tests.jar”文件没有任何条目,但主阴影 jar 看起来不错(尽管它不包含任何测试类)。
另外,这个问题重复了另一个问题,尽管接受的答案并不真正令人满意: 如何在 maven-shade-plugin 创建的 Jar 中包含测试类?
With version 2.2 of the maven-shade-plugin, they added a "shadeTestJar" option (see MSHADE-158): http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#shadeTestJar
However, I tried using this and couldn't get it to work. Here's my plugin config:
The "...-tests.jar" file has no entries, but the main shaded jar looks fine (although it doesn't contain any test classes).
Also, this question duplicates this other question, although the accepted answer isn't real satisfying: How to include test classes in Jar created by maven-shade-plugin?
我已经成功地通过添加以下内容使其工作:
I've managed to make it work by adding :
尝试像这样
include
您的测试包:Try
include
ing your test packages like this:按照上面 ~steve-k 的解释使用
maven-shade-plugin
是正确的,不幸的是,由于 bugshadeTestJar
不起作用,并且生成的测试 JAR 是空的。Using the
maven-shade-plugin
as explained by ~steve-k above is correct, unfortunately due to a bugshadeTestJar
doesn't work and the resulting test JAR is empty.