Is there a way to load Maven Surefire Plugin exclusions list from a file?

谁都会走 提交于 2019-12-11 07:01:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/41644760/is-there-a-way-to-load-maven-surefire-plugin-exclusions-list-from-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!