Travis CI + Coverity 扫描 Gradle

Travis CI + Coverity scan with Gradle

我已经成功 setup a project 使用 Travis CI 进行构建和测试。现在我正在尝试添加 Coverity Scan。

我创建了一个名为 coverity_scan 的分支并将其设置为用于覆盖构建。在我将提交推送到该分支后,我可以在 Travis CI 构建控制台中看到 Coverity 工具开始执行其工作:

Coverity Scan analysis selected for branch coverity_scan.
Coverity Scan analysis authorized per quota.

...

Running Coverity Scan Analysis Tool...

Travis 构建成功,在 Coverity build-log.txt 文件中我看到了这个:

2016-10-06T21:02:39.132946Z|cov-build|2665|info|> 
2016-10-06T21:02:39.132946Z|cov-build|2665|info|> Build time (cov-build overall): 00:01:36.812431
2016-10-06T21:02:39.132946Z|cov-build|2665|info|> 
2016-10-06T21:02:39.134719Z|cov-build|2665|info|> Build time (Java emits total): 00:01:07.595656
2016-10-06T21:02:39.134719Z|cov-build|2665|info|> 
2016-10-06T21:02:39.134719Z|cov-build|2665|info|> 
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> Emitted 30 Java compilation units (100%) successfully
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> [WARNING] Recoverable errors were encountered during 1 of these Java compilation units.
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> 
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> 30 Java compilation units (100%) are ready for analysis
2016-10-06T21:02:39.134763Z|cov-build|2665|info|>  For more details, please look at: 
2016-10-06T21:02:39.134763Z|cov-build|2665|info|>     /home/travis/build/Edvinas01/chat-rooms/server/cov-int/build-log.txt

然而,完成后,我没有在项目 Coverity 仪表板中看到任何提交的构建或更改。项目状态保持在 pending.

我已按照 this 指南设置我的 .travis.yml 文件,如下所示:

language: java
jdk:
  - oraclejdk8
before_script:
  - cd server
  - chmod +x gradlew
script:
  # Run tests when not on coverity branch.
  - if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then
      ./gradlew check;
    fi
cache:
  directories:
  - ~/.gradle
after_success:
  # Upload coveralls when not on coverity branch.
  - if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then
      ./gradlew cobertura coveralls;
    else
      cat cov-int/build-log.txt;
    fi
notifications:
  email:
    on_success: change
env:
  matrix:
    - TERM=dumb
  global:
    # COVERITY_SCAN_TOKEN
    - secure: "<TOKEN>"
before_install:
  - echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
addons:
  coverity_scan:
    project:
      name: "Edvinas01/chat-rooms"
      description: "Build submitted via Travis CI"
    notification_email: "<EMAIL>"
    build_command_prepend: "./gradlew clean"
    build_command: "./gradlew build"
branch_pattern: coverity_scan

我是否必须指定一些额外的配置才能发布我的 Coverity 构建?

有时间用 java 和覆盖率分析工具创建了一个虚拟机。在提取我的项目和 运行 工具后,我在日志中注意到了这一点:

[WARNING] No files were emitted. This may be due to a problem with your configuration
or because no files were actually compiled by your build command.

在摆弄了很多东西并查看了其他项目之后,我发现这是由于 Gradle 版本造成的。我的项目使用的是 3.0,所以我降级到 2.14.1,它终于可以正常工作了。

值得一提的是,将 Coverity 与任何 Gradle 版本一起使用都没有问题,只要您确保您没有使用守护程序(只是为了确保您可以指定 --no-daemon 在命令行上)。

也就是说,还有许多其他容易遗漏的陷阱,导致不太明显的错误消息。

有关有用的背景,请在此处查看 Caleb 的回答:

工作示例可以参考这个项目:

https://github.com/ddimtirov/nuggets