当使用maven-surefire-plugin并且两者都包括和排除时,它们处理的顺序是什么?此外,如果您有3组测试,第一组是基本集,第二组和第三组是特殊情况,那么可以使用概要文件进一步包括/排除吗?配置文件包括/排除设置将如何合并?例如,我想做这样的事情:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>connectedToProdNetwork</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>/org/mycompany/dataset/test/ExtractProd*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>runForAsLongAsYouNeed</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>/org/mycompany/dataset/test/LargeDataset*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>然后就能像这样跑了
mvn package -P connectedToProdNetwork或
mvn package -P runForAsLongAsYouNeed或
mvn package -P connectedToProdNetwork,runForAsLongAsYouNeed使用mvn help:effective-pom -P [profileA],我能够确定,如果我指定了一个配置文件,那么产生的有效pom将是:
<configuration>
<includes>
<include>[includeFromProfileA]</include>
</includes>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>如果我提供了多个配置文件,mvn help:effective-pom -P [profileA],[profileB]
<configuration>
<includes>
<include>[includeFromProfileAOrBSeeminglyArbitraryChoice]</include>
</includes>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>最后,如果我将属性combine.children="append"添加到配置文件配置的<includes>元素中,并提供这两个配置文件,那么mvn help:effective-pom -P [profileA],[profileB]
<configuration>
<includes combine.children="append">
<include>[includeFromProfileA]</include>
<include>[includeFromProfileB]</include>
</includes>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>但是,既然每个文件都被指定为<include>和<exclude>,那么会发生什么呢?
-更新2-
实际上,使用此配置运行构建:
<configuration>
<includes>
<include>**/TestA.java</include>
</includes>
<excludes>
<exclude>**/TestA.java</exclude>
</excludes>
</configuration>不是运行TestA,所以看起来<exclude>会压倒<include>。注意,为了完整起见,我确实颠倒了顺序,将<excludes>放在<includes>之前,但是行为没有改变。如果有人能在缺少源代码的地方找到这样的行为,我很乐意给他们答案.
发布于 2015-11-27 23:01:02
我找不到有关尽责插件的正式文档,但实际上,exclude-override是一种常见的方法,Maven也在其他类似的环境中应用,比如资源。
唯一的官方相关信息(我发现)来自官方的Maven POM参考文档,这里
包括:一组文件模式,它使用*作为通配符指定要包含的文件作为该指定目录下的资源。 排除:与相同的结构,但指定要忽略哪些文件。在包含和排除之间的冲突中,排除。
注意:我在有趣的语句中添加了最后的粗体格式。
因此,在官方的maven插件中使用的方法可能比相同的更多(通常,所有具有org.apache.maven.plugins groupId和maven前缀的插件都是artifactId)。
发布于 2015-04-09 10:16:22
你试过使用JUnit类别吗?
使用这种方法,您可以为测试提供许多不同的类别,并使用它而不是类名排除/包括它们。这将是一种更可扩展的方法。
https://stackoverflow.com/questions/11959211
复制相似问题