当maven与Cobertura报告和安装目标一起运行时,Cobertura检查失败

时间:2014-10-22 14:15:00

标签: maven cobertura maven-cobertura-plugin

我在我的pom中设置了Cobertura:

...
<build>
...
<plugins>
...
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>${cobertura-maven-plugin.version}</version>
    <configuration>
        <formats>
            <format>html</format>
        </formats>
        <outputDirectory>${project.build.directory}</outputDirectory>
        <check>
            <haltOnFailure>${testsAreRun}</haltOnFailure>
            <totalBranchRate>27</totalBranchRate>
            <totalLineRate>88</totalLineRate>
        </check>
        <instrumentation>
            <ignoreTrivial>true</ignoreTrivial>
            <excludes>
                <exclude>something/app/**/*.class</exclude>
                <exclude>something/config/**/*.class</exclude>
            </excludes>
        </instrumentation>
    </configuration>
    <executions>
        <execution>
            <phase>verify</phase>
            <goals>
                <goal>clean</goal>
                <!--<goal>cobertura</goal>-->
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>
...
<plugins>
...
<build>
...

如果我跑:

mvn clean cobertura:cobertura

一切顺利。如果我跑:

mvn clean install

一切顺利。但是,如果我跑:

mvn clean cobertura:cobertura install

安装过程中构建失败,说我的代码覆盖率为0%,即:

[ERROR] Oct 22, 2014 3:03:59 PM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler loadCoverageData
INFO: Cobertura: Loaded information on 8 classes.
Project failed check. Total branch coverage rate of 0.0% is below 27.0%
Project failed check. Total line coverage rate of 0.0% is below 88.0%

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.839 s
[INFO] Finished at: 2014-10-22T15:03:59+01:00
[INFO] Final Memory: 38M/469M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.6:check (default) on project something: Coverage check failed. See messages above. -> [Help 1]

任何想法为什么?

1 个答案:

答案 0 :(得分:0)

当你跑步时:

  

mvn cobertura:cobertura

它刚刚生成了报告。

当你跑

  

mvn install

它会运行您在那里设置的所有插件,包括您已设置的具有线路和分支检查的配置