有没有办法从文件加载Maven Surefire插件排除列表? [英] Is there a way to load Maven Surefire Plugin exclusions list from a file?
问题描述
在Surefire插件中,您有一个排除文件(或正则表达式)的列表,如下所示:
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>
我想在排除列表中添加一堆与正则表达式不匹配的文件.该列表大约有200个文件(一个古怪的收藏).我想从Maven pom.xml
外部的文件中添加这些文件.
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
.
我认为有一种方式使用maven属性插件执行此操作.我看不到如何加载
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?
推荐答案
The Surefire plugin provides exactly the configuration element for this, called excludesFile
:
包含排除模式的文件.空行或以
#
开头的行将被忽略.如果还指定了excludes
,则将附加这些模式.带有路径,简单和正则表达式的示例不包括:*/test/*
**/DontRunTest.*
%regex[.*Test.*|.*Not.*]
A file containing exclude patterns. Blank lines, or lines starting with
#
are ignored. Ifexcludes
are also specified, these patterns are appended. Example with path, simple and regex excludes:*/test/*
**/DontRunTest.*
%regex[.*Test.*|.*Not.*]
该插件的2.19版在 SUREFIRE-1065 和 SUREFIRE-1134 .这样,您可以直接在项目的基本目录中找到一个名为surefireExcludes.txt
的文件,其中包含
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>
所有测试都将运行,但与文件中指定的模式匹配的测试除外.如果模式以#
开头,则甚至可以将其注释掉.也可以使用surefire.excludesFile
用户属性(即:
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
参数 includesFile
也存在相反的要求.
The parameter includesFile
also exists for the opposite requirement.
这篇关于有没有办法从文件加载Maven Surefire插件排除列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!