我如何配置maven树荫插件以在我的jar中包含测试代码? [英] How can I configure the maven shade plugin to include test code in my jar?

查看:221
本文介绍了我如何配置maven树荫插件以在我的jar中包含测试代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用阴影maven插件来构建我的项目,以便将它的所有依赖项都包含在一个jar中(这使得它可以更轻松地在Hadoop上运行)。 Shade似乎默认排除我的测试代码,这是可以理解的。由于我想对我的集群运行集成测试,我希望能够设置另一个配置文件来为此创建一个单独的jar。有什么办法可以配置这个插件来包含测试代码?

解决方案

使用maven-shade-plugin 2.2版本,他们添加了shadeTestJar选项(请参阅MSHADE-158): http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#shadeTestJar



然而,我试过使用这个,并不能得到它的工作。这是我的插件配置:

 < plugin> 
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-shade-plugin< / artifactId>
< version> 2.2< / version>
<执行次数>
<执行>
<阶段>包< /阶段>
<目标>
<目标>阴影< /目标>
< /目标>
<配置>
< shadeTestJar> true< / shadeTestJar>
< / configuration>
< /执行>
< /执行次数>
< / plugin>

...- tests.jar文件没有条目,但主要着色的jar外观罚款(虽然它不包含任何测试类)。

此外,这个问题重复了这个问题,尽管接受的答案并不真实令人满意:如何将测试类包含在由maven-阴影插件?


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?

解决方案

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:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadeTestJar>true</shadeTestJar>
            </configuration>
        </execution>
    </executions>
</plugin>

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?

这篇关于我如何配置maven树荫插件以在我的jar中包含测试代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆