我有一个多模块Maven项目,在父POM.xml中定义了JaCoCo,如下所示:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<!-- Ensures classes have 80+% line and branch coverage. -->
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
<rule>
<!-- Ensures a module has at 80+% coverage,and all classes have at least some coverage. -->
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<limit>
<counter>CLASS</counter>
<value>MISSEDCOUNT</value>
<minimum>0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
运行良好,但是我注意到,如果有一个没有Test
类的模块,JaCoCo将不会运行,并且不会使构建失败。
我可以看到在这些模块中调用了该插件:
[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (default) @ my-module ---
[INFO] argLine set to -javaagent:/Users/######/.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/Projects/#####/my-module/target/jacoco.exec
但是它会跳过执行:
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ my-module ---
[INFO] No tests to run.
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.5:report (report) @ my-module ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ my-module ---
[INFO] Building jar: /Projects/#####/my-module/target/my-module-0.0.1.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.5:check (check) @ my-module ---
[INFO] Skipping JaCoCo execution due to missing execution data file:/Projects/#####/my-module/target/jacoco.exec
[INFO]
这是有意提供的功能吗,有什么方法可以确保在这些情况下失败?