我已经使用maven-jar-plugin
创建了一个测试-JAR<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>
但是测试-JAR需要主要类,因此如何将它们包含在测试中(创建像Uber-Test-jar之类的东西(?
通常我两次导入依赖关系:
- 常规的;
- 带有范围的测试罐=测试。
使您没有缺少课程的问题。但是,如果您不需要应用程序中的主要来源(第一个依赖关系(,而它们仅用于测试,则还可以将其切换为测试。
<scope>test</scope>
您不能将其他类添加到test-jar槽Maven-jar-plugin中,但是您可以按其他方式进行包含主要项目类和测试类的JAR:使用:maven-sembly-plugin!
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptor>src/assembly/dep.xml</descriptor>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
这将创建一个文物,其中包含汇编描述符中描述的信息,描述符默认路径为src/soupdybly/.xml在描述符中,您要添加此信息:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly- plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>example</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.testOutputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
- id-> jar的后缀
- 格式 ->输出文件的格式(我们正在创建一个JAR(
- 文件集 ->添加的所有目录
- fileset->与outputDirectory一起添加的单个目录,包括排除ECC。
此示例将用-example创建一个JAR作为Postfix(Ex:plugin-1.0-example.jar(,带有主和测试文件