How to include test classes in Jar created by maven-shade-plugin?(如何在 maven-shade-plugin 创建的 Jar 中包含测试类?)
问题描述
我正在尝试使用 Maven 将我的测试类打包到一个带有依赖项的可执行 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.
到目前为止,这是我的 pom.xml:
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>
当我执行 mvn clean package 时,构建会创建 3 个 jar:
When I execute mvn clean package the build creates 3 jars:
- executable-tests-1.0.jar//由mvn包阶段构建
- executable-tests-1.0-teststjar//由 jar-plugin 构建
- cucumber-tests.jar//由 shade-plugin 构建
Cucumber-tests.jar 包含 info.cuke 依赖项,但不包含 executable-tests-1.0-tests.jar.
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?
我已经将我的示例项目推送到 GitHub,如果有人喜欢玩它的话:) https://github.com/C0deAttack/ExecutableTests
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.
首先我使用 maven-dependency-plugin 获取依赖并在本地解包,然后我使用 maven-jar-plugin 创建一个 test-jar 并包含解压后的依赖项中的类.
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 中包含测试类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 maven-shade-plugin 创建的 Jar 中包含测试类?
基础教程推荐
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
