如何在由maven-shade-plugin创建的Jar中包含测试类? [英] How to include test classes in Jar created by maven-shade-plugin?
问题描述
我是试图将我的测试类打包到一个使用Maven的依赖关系的可执行jar中,但是我很努力地得到这个正确的。 pom.xml到目前为止:
< project>
< modelVersion> 4.0.0< / modelVersion>
< groupId> com.c0deattack< / groupId>
< artifactId> executable-tests< / artifactId>
< version> 1.0< / version>
< packaging> jar< / packaging>
< name> executable-tests< / name>
<依赖关系>
<依赖关系>
< groupId> info.cukes< / groupId>
< artifactId> cucumber-java< / artifactId>
< version> 1.0.0< / version>
< / dependency>
<依赖关系>
< groupId> info.cukes< / groupId>
< artifactId> cucumber-junit< / artifactId>
< version> 1.0.0< / version>
< / dependency>
< dependency>
< groupId> org.seleniumhq.selenium< / groupId>
< artifactId> selenium-java< / artifactId>
< version> 2.21.0< / version>
< / dependency>
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.10< / version>
< / dependency>
< / dependencies>
< build>
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-jar-plugin< / artifactId>
< version> 2.4< / version>
<执行>
< execution>
< goals>
< goal> test-jar< / goal>
< / goals>
< / execution>
< / executions>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-shade-plugin< / artifactId>
< version> 1.6< / version>
<执行>
< execution>
< phase> package< / phase>
< goals>
< goal> shade< / goal>
< / goals>
< configuration>
< finalName> cucumber-tests< / finalName>
<变压器>
< transformer implementation =org.apache.maven.plugins.shade.resource.ManifestResourceTransformer>
< mainClass> cucumber.cli.Main< / mainClass>
< / transformer>
< / transformers>
< artifactSet>
< includes>
< include> info.cukes:*< / include>
< / includes>
< / artifactSet>
< / configuration>
< / execution>
< / executions>
<依赖关系>
<依赖关系>
< groupId> com.c0deattack< / groupId>
< artifactId> executable-tests< / artifactId>
< version> 1.0< / version>
< type> test-jar< / type>
< / dependency>
< / dependencies>
< / plugin>
< / plugins>
< / build>
< / project>
当我执行 mvn clean package
创建3个jar:
- 可执行文件-test-1.0.jar //由mvn包相位构建
- executable-tests-1.0-teststjar //由jar-plugin建立
- cucumber-tests.jar //由阴影插件构建
Cucumber-tests.jar
包含 info.cuke
依赖关系,但它不包含 executable-tests-1.0-tests.jar
。
我已经完成各种各样的东西要尝试并且包含测试课,但没有任何工作,我还缺少什么?
编辑:我已经推我的示例项目到GitHub如果有任何幻想玩弄:) :) https://github.com/C0deAttack/ExecutableTests
我以一种不同的方式解决了我的问题;使用另外两个插件。
首先,我使用 maven-dependency-plugin
获取依赖关系并在本地解压缩,然后我使用 maven-jar-plugin
创建一个 test-jar
,并从未打包的依赖项中包含类。
I'm trying to package my test classes in to an executable jar with dependencies using Maven, but I'm struggling to get this right.
This is my pom.xml so far:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.c0deattack</groupId>
<artifactId>executable-tests</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>executable-tests</name>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.21.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>cucumber-tests</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cucumber.cli.Main</mainClass>
</transformer>
</transformers>
<artifactSet>
<includes>
<include>info.cukes:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.c0deattack</groupId>
<artifactId>executable-tests</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
When I execute mvn clean package
the build creates 3 jars:
- executable-tests-1.0.jar // built by the mvn package phase
- executable-tests-1.0-teststjar // built by the jar-plugin
- cucumber-tests.jar // build by the shade-plugin
Cucumber-tests.jar
contains the info.cuke
dependencies but it doesn't contain the executable-tests-1.0-tests.jar
.
I've done all sorts of things to try and have the test classes included but nothing has worked, what am I missing?
Edit: I've pushed my example project to GitHub if any one fancies playing around with it :) https://github.com/C0deAttack/ExecutableTests
I've solved my problem a different way; using two other plugins.
First I use the maven-dependency-plugin
to get the dependencies and unpack them locally, then I use the maven-jar-plugin
to create a test-jar
and include the classes from the unpacked dependencies.
这篇关于如何在由maven-shade-plugin创建的Jar中包含测试类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!