Cobertura 检查 Travis 失败 CI

Cobertura Checks Fail on Travis CI

在我的 Maven 构建中,我使用 Cobertura 检查是否存在一定的最小覆盖率:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.5.2</version>
    <configuration>
        <check>
            <branchRate>100</branchRate>
        </check>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>cobertura</goal>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

当运行 mvn install时,这工作正常。但是,在 Travis CI 中,构建失败,因为 Travis first runs mvn install -DskipTests=true 无法获取依赖项。显然,当测试被跳过时,没有覆盖,因此整个构建失败:

[ERROR] ch.trick17.betterchecks.fluent.StringCheck failed check. Branch coverage rate of 0.0% is below 100.0%
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...
[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.5.2:check (default) on project better-checks-core: Coverage check failed. See messages above. -> [Help 1]

我能否以某种方式配置 Cobertura 以在跳过测试时跳过检查?或者是否有任何其他解决方案,也许在 Travis 方面?


这是我的 .travis.yml 文件:

language: java

jdk:
  - openjdk6
  - openjdk7
  - oraclejdk7
  - oraclejdk8

script: "mvn install"

您可以通过以下方式转换:install: true which skips the install step

作为 kmarbaise 答案的替代方案,您可以替换为自定义它 skips the Cobertura check:

,而不是完全关闭安装步骤
install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dcobertura.skip=true -B -V

这样一来,实际构建脚本的输出就不会与下载依赖项和 Maven 插件的输出混淆。