Performing tests after packaging

One of my projects needs a rather complicated setup for the resulting JAR file, so I would like to run the test after the package phase to make sure that the JAR contains what it needs.

How do I do this with Maven 2?

+4
source share
2 answers

Transform your project into a multi-module assembly . In the first module, create an original project. In the second module, add the dependency to the first.

This will add the first JAR to the classpath.


Update from OP: this works, but I had to add this to my POM:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${version.maven-surefire-plugin}</version> <configuration> <useSystemClassLoader>false</useSystemClassLoader> </configuration> </plugin> 

The important part is <useSystemClassLoader>false</useSystemClassLoader> . Without this, my class path only contained a couple of JAR virtual machines, as well as a boot JAR (which contains the class test path in MANIFEST.MF ). I do not know why this class test path is not visible from the classes loaded from it.

+3
source

You can use the surefire plugin for this. you need to associate the phase with the execution (see below). You will need to change the phase so that it is in your case one after the packaging phase.

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> <executions> <execution> <id>unittests</id> <phase>test</phase> <goals> <goal>test</goal> </goals> <configuration> <skip>false</skip> <includes> <include>**/**/**/*Test.java</include> </includes> </configuration> </execution> </executions> </plugin> 
+5
source

All Articles