由于jacoco-maven-plugin与maven-surefire-plugin插件均使用argLine参数,导致surefire覆盖了jacoco的参数,而无法生成jacoco.exec,maven报错:Skipping JaCoCo execution due to missing execution data file
在jacoco中加入propertyName参数,在surefire中的argLine中引入,即可解决此问题,pom配置如下:
<!-- 单元覆盖率插件-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacocoArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 排除部分类的单元测试,如controller-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<argLine>-Xmx256M ${jacocoArgLine}</argLine>
<skip>false</skip>
<testFailureIgnore>false</testFailureIgnore>
<includes></includes>
<excludes>
<!-- 由于测试controller类需要启动auth应用进行登录请求,故剔除 -->
<exclude>**/controller/*ControllerTest.java</exclude>
</excludes>
</configuration>
</plugin>