Maven: excluding tests from assembly
I have several classes that I use as tests in my src / test / java folder of my project. When I start maven using the standard maven plugin compile. These elements are compiled into .class files and are included in the jar where the compiled code is packaged.
I created these tests for myself to work in Eclipse, before starting maven and building my release. These are just sanity tests and should not be included in the build. I would rather not put them in a separate project because it makes sense to me. How can I tell maven that I don't want it to compile / include files in this directory?
I believe the maven compiler generates the jar like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
source to share
As I understand from your comment on this answer , "tests" are not unit tests, but just regular classes that you want to exclude from the final artifact? Thus, the best option is to use the tag <exclude>
with the maven-jar-plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/yoursortoftestpackage/YourSortOfTestClass*</exclude>
</excludes>
</configuration>
</plugin>
Hope it helps!
Greetings,
source to share
Junit annotations @Ignore
will ignore the class when building in maven.
Edit:
You can customize the maven-surefire-plugin.
<project>
<build>
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
source to share