2012-08-14 35 views
15

当使用maven-surefire-plugin并且包含和排除时,它们处理的是哪些订单?此外,如果您有三组测试,第一组为基础组,第二组和第三组为特殊情况,您是否可以使用配置文件进一步包含/排除?如何将配置文件包含/排除设置合并?例如,我愿做这样的事情:maven-surefire-plugin包含/排除优先

<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 

---- UPDATE -----

使用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> 

是否运行种皮,因此才出现了<exclude>会压倒<include>请注意,为了完整起见,我确实颠倒了订单并在<includes>之前放置了<excludes>,但行为并未发生变化。如果任何人可以找到的地方短的源代码行为概述,我会很乐意给他们的答案...

+3

排除覆盖包括因为通常人们包括比他们需要的更大的集合,只需要一些取出。这通常使得列表更短,工作更少。 – Steven 2012-08-14 23:28:28

+0

@Steven,是的,它符合我在测试过程中的经历。你知道在哪里这是_officially_陈述,以便我知道他们不会在未来改变这种行为?无论如何,谢谢你。 – Lucas 2012-08-16 16:57:19

+0

我认为实验方法往往是最好的确定:) - 仍然:pom参考给出了关于顺序的一些提示:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle .html - 例如。继承执行首先运行。插件使用排除/包含按照pom的顺序通常很常见。所以你可以包括一些特殊的东西,但不包括全部或包含所有东西,并排除特殊的东西有疑问的命令将遵循(在大多数情况下,插件) – wemu 2015-02-03 12:40:11

回答

4

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

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

包括:一组文件模式,其指定的文件,包括在根据该资源指定的目录,使用*作为通配符。

不包括:与包含结构相同,但指定要忽略的文件。 在包含和排除之间的冲突中,排除胜利

注:我在有趣的声明中添加了最终的粗体格式。

因此,在官方的maven插件中可能会使用相同的方法(一般来说,所有插件的org.apache.maven.plugins groupId和maven-前缀都是artifactId)。

+1

伟大的发现...不知道我应该将它标记为答案,因为它不是技术上确定的,但绝对_userful_信息。 – Lucas 2015-11-29 19:28:08