Home > java, maven > Maven test-jar and test code reuse

Maven test-jar and test code reuse

In a multi module Maven project you might want to reuse test-related code (in src/test) across modules.

The recommended way is described here:
http://maven.apache.org/guides/mini/guide-attached-tests.html

You might want to exclude test classes from test-jar, to prevent that they run multiple times. Add this to your maven-jar-plugin definition (right after the <goals>..</goals> section) :

<configuration>
    <excludes>
        <exclude>**/*Test.class</exclude>
    </excludes>
</configuration>

This assumes that your test classes and only your test classes are named “…Test”.

More info on maven-jar-plugin configuration options for the test-jar goal:
http://maven.apache.org/plugins/maven-jar-plugin/test-jar-mojo.html

Advertisements
Categories: java, maven
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: