1

In the Surefire plugin, you have have an exclusions list of files (or regex) like this:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <excludes>
            <exclude>**/TestCircle.java</exclude>
            <exclude>**/TestSquare.java</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

I want to add a bunch of files to my exclusions list that don't match a regex. This list is about 200 files (an eccentric collection). I'd like to add those files from a file external to my Maven pom.xml.

I think there is a way to do this using the maven properties plugin. I can't see how that would load a variable into a list though.

Is there a way to load the exclusions list from a file?

Community
  • 1
  • 1
hawkeye
  • 34,745
  • 30
  • 150
  • 304

1 Answers1

3

The Surefire plugin provides exactly the configuration element for this, called excludesFile:

A file containing exclude patterns. Blank lines, or lines starting with # are ignored. If excludes are also specified, these patterns are appended. Example with path, simple and regex excludes: */test/*
**/DontRunTest.*
%regex[.*Test.*|.*Not.*]

It was introduced in version 2.19 of the plugin as part of SUREFIRE-1065 and SUREFIRE-1134. As such, you could directly have a file called surefireExcludes.txt at the base directory of your project, containing

**/TestCircle.java
**/TestSquare.java
# **/TestRectangle.java A commented-out pattern

and then configure the plugin with:

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.19.1</version>
  <configuration>
    <excludesFile>surefireExcludes.txt</excludesFile>
  </configuration>
</plugin>

All of the tests will be run, except for those matching the patterns specified in the file. The patterns can be even commented-out if they start with #. This could also be passed directly on the command-line with the surefire.excludesFile user property, i.e.:

mvn clean test -Dsurefire.excludesFile=surefireExcludes.txt

The parameter includesFile also exists for the opposite requirement.

Tunaki
  • 132,869
  • 46
  • 340
  • 423