2016-08-17 54 views
2

我有大约5000个测试用例的大项目。在运行mvn clean install时,它将两次运行test目标(其中一个作为安装的一部分,第二次作为surefire插件的一部分)。如何停止运行两次测试的maven?

为什么需要第二次运行test?并且在那里强迫surefire使用test目标结果而不是重新调用它自己的结果? 我认为这是浪费时间和机器资源,特别是最近第二轮运行test造成PermGen构建错误,无论我将多大的堆泵入maven runner,它仍然会在第二轮测试中死亡。

这是我的神火pluging配置:

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.18.1</version> 
    <executions> 
     <execution> 
     <id>default-test</id> 
     <phase>test</phase> 
     <goals> 
      <goal>test</goal> 
     </goals> 
     <configuration> 
      <parallel>classes</parallel> 
      <threadCount>3</threadCount> 
     </configuration> 
     </execution> 
    </executions> 
</plugin> 

是否有办法来调整该插件可以更好地处理机器的资源?

这里是一个被执行的全默认的Maven简介:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.0.2</version> 
      <configuration> 
       <archive> 
        <manifest> 
         <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 
        </manifest> 
        <manifestEntries> 
         <Build-Number>${build.number}</Build-Number> 
         <Job-Name>${job.name}</Job-Name> 
         <Build-Url>${build.url}</Build-Url> 
         <Git-Commit>${git.commit}</Git-Commit> 
         <Git-Branch>${git.branch}</Git-Branch> 
         <Timestamp>${maven.build.timestamp}</Timestamp> 
         <StyleGuide-Version>${styleguide.version}</StyleGuide-Version> 
        </manifestEntries> 
       </archive> 
       <warName>pss</warName> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>com.cj.jshintmojo</groupId> 
      <artifactId>jshint-maven-plugin</artifactId> 
      <version>1.3.0</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>lint</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <options>maxparams:5,camelcase,eqeqeq,forin,immed,latedef,noarg,noempty,nonew,expr</options> 
       <directories> 
        <directory>src/main/webapp/js/page</directory> 
       </directories> 
       <excludes> 
        <exclude>src/main/webapp/js/page/marketingPreferences.js</exclude> 
        <exclude>src/main/webapp/js/page/changeCarParkingDetails.js</exclude> 
        <exclude>src/main/webapp/js/page/angularjs-app.js</exclude> 
        <exclude>src/main/webapp/js/page/content-cover.js</exclude> 
        <exclude>src/main/webapp/js/page/amendmentConfirm.js</exclude> 
       </excludes> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.lesscss</groupId> 
      <artifactId>lesscss-maven-plugin</artifactId> 
      <version>1.3.3</version> 
      <executions> 
       <execution> 
        <id>bingleless</id> 
        <configuration> 
         <sourceDirectory>${project.basedir}/src/main/webapp/app-resources/</sourceDirectory> 
         <outputDirectory>${project.basedir}/src/main/webapp/app-resources/</outputDirectory> 
         <includes> 
          <include>**\/policy-self-service\/**\/*pss-sg.less</include> 
         </includes> 
         <compress>true</compress> 
        </configuration> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>net.alchim31.maven</groupId> 
      <artifactId>yuicompressor-maven-plugin</artifactId> 
      <version>1.1</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>compress</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <excludes> 
        <exclude>**/*.min.js</exclude> 
        <exclude>**/*.min.css</exclude> 
        <exclude>**/style-guide/**</exclude> 
        <exclude>**/generated/**</exclude> 
        <exclude>**/app-resources/common/**</exclude> 
        <exclude>**/app-resources/bower_components/**</exclude> 
        <exclude>**/app-resources/policy-self-service/**</exclude> 
       </excludes> 
       <nosuffix>true</nosuffix> 
       <jswarn>false</jswarn> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-checkstyle-plugin</artifactId> 
      <configuration> 
       <logViolationsToConsole>true</logViolationsToConsole> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>${maven-surefire-plugin.version}</version> 
      <configuration> 
       <parallel>classes</parallel> 
       <threadCount>3</threadCount> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-report-plugin</artifactId> 
      <version>${maven-surefire-report-plugin.version}</version> 
      <executions> 
       <execution> 
        <phase>install</phase> 
        <goals> 
         <goal>report-only</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
+0

您是否尝试删除执行部分? – Zelldon

+0

请添加(trimmed)'mvn clean install'的输出,特别是以'[INFO] - maven-surefire-plugin'开头的行 - 应该帮助追踪插件何时执行和执行多少次。 –

+0

它只运行一次,你有其他插件吗? – ravthiru

回答

2

我想在你的pom.xml导致第二次试运行<execution>。除了测试阶段的默认目标之外,Maven还将其视为另一个执行目标。

由于maven-surefire-plugin是默认在Maven中用于测试阶段的插件,因此您只需要在<execution>之外提供<configuration>部分。修改您的pom.xml如下

<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.18.1</version> 
    <configuration> 
     <parallel>classes</parallel> 
     <threadCount>3</threadCount> 
    </configuration> 
    </plugin> 
</plugins> 
+0

这是正确的,因为maven-surefire-plugin默认已经绑定到生命周期。最好的是给配置通过pluginManagement,而不是在构建.. – khmarbaise

+0

@Rocherlee试过,也没有工作。仍然调用两次TESTS。 – DhafirNz