[英]How to include test classes in Jar created by maven-shade-plugin?
[英]How can I configure the maven shade plugin to include test code in my jar?
我使用shade maven插件来构建我的项目,以便它的所有依赖项都包含在一个jar中(这使得在Hadoop上运行它更容易)。 默认情况下,Shade似乎排除了我的测试代码,这是可以理解的。 由于我想对我的集群运行集成测试,我希望设置另一个配置文件来为此目的构建一个单独的jar。 有没有办法配置这个插件还包括测试代码?
使用版本2.2的maven-shade-plugin,他们添加了一个“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>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadeTestJar>true</shadeTestJar>
</configuration>
</execution>
</executions>
</plugin>
“...- tests.jar”文件没有条目,但主阴影jar看起来很好(尽管它不包含任何测试类)。
此外,这个问题重复了另一个问题,虽然接受的答案并不真正令人满意: 如何在maven-shade-plugin创建的Jar中包含测试类?
最后几个答案是最好的破解功能的混乱解决方法。 事情的事实仍然是maven-shade-plugin
中存在一个错误。 与此同时,我已经调查并根本导致了这个bug,并创建了一个补丁 。 现在我希望Apache的某个人很快就会包含它,然后最终的shadeTestJar
功能可以像它应该的那样工作。
我已经设法通过添加:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/test/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
使用上面~steve -k所解释的maven-shade-plugin
是正确的,遗憾的是由于一个bug,因为shadeTestJar
不起作用,结果测试JAR为空。
尝试include
的测试包:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.apache.maven:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.