I want to package my test package to jar file . How to execute generate test-jar from maven plugin Surefire.
Asked
Active
Viewed 2.4k times
2 Answers
41
By using the following configuration you can create a jar from your tests:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
To use such kind of artifact:
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<type>test-jar</type>
<version>version</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
khmarbaise
- 87,368
- 28
- 173
- 215
-
@khmarbaise Where do it use dependency ? Is it in the same pom.xml? – fjjiaboming Jun 08 '16 at 03:13
-
No. The first code block is for the application that should generate a JAR file with test-scoped classes. The second code block is for application that want to use the generated JAR file. – Manuel Dec 03 '20 at 12:35
24
You can add following entries to your pom:
<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>
Sergey Vyacheslavovich Brunov
- 13,242
- 7
- 41
- 75
Dharshana
- 1,182
- 1
- 8
- 18