gpt4 book ai didi

java - maven-surefire-plugin 包含/排除优先级

转载 作者:IT老高 更新时间:2023-10-28 20:54:32 25 4
gpt4 key购买 nike

当使用 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>但行为并没有改变。如果有人能找到概述这种行为的源代码之外的地方,我很乐意给他们答案......

最佳答案

我找不到关于 surefire 插件的官方文档,但确实 exclude-override-include 是一种常见的方法,Maven 也将其应用于其他类似的上下文中,例如资源。

唯一的官方相关信息(我发现)来自官方 Maven POM 引用文档,here :

includes: A set of files patterns which specify the files to include as resources under that specified directory, using * as a wildcard.

excludes: The same structure as includes, but specifies which files to ignore. In conflicts between include and exclude, exclude wins.

注意:我在有趣的语句中添加了最后的粗体格式。

因此,在官方 maven 插件中很可能使用相同的方法(通常,所有插件都具有 org.apache.maven.plugins groupId 和 maven- 前缀作为 artifactId)。

关于java - maven-surefire-plugin 包含/排除优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11959211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com