这是用户在 2024-9-23 14:57 为 https://plugins.jenkins.io/jacoco/ 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

JaCoCo 嘉可可

jacoco-plugin jacoco 插件

Build Status Build Status Release

Jenkins Plugin GitHub release Jenkins Plugin Installs

A plugin for Jenkins to capture and visualize code coverage testing results for projects using JaCoCo for code-coverage analysis.
Jenkins 的插件,用于使用 JaCoCo 进行代码覆盖率分析来捕获和可视化项目的代码覆盖率测试结果。

More information can be found on the Wiki page https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin
更多信息可以在 Wiki 页面上找到:https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin

Available options are described at https://www.jenkins.io/doc/pipeline/steps/jacoco/
可用选项的描述见 https://www.jenkins.io/doc/pipeline/steps/jacoco/

Note: Version 2.0.0 and higher requires using JaCoCo 0.7.5 or newer, if your projects still use JaCoCo 0.7.4, the plugin will not display any code-coverage numbers any more! In this case please use version 1.0.19 until you can update jacoco in your codebase.
注意:2.0.0及更高版本需要使用JaCoCo 0.7.5或更高版本,如果您的项目仍然使用JaCoCo 0.7.4,该插件将不再显示任何代码覆盖率数字!在这种情况下,请使用版本 1.0.19,直到您可以更新代码库中的 jacoco。

Using as part of a pipeline via Jenkinsfile
通过 Jenkinsfile 作为管道的一部分使用

The following is an example snippet that can be used in a Jenkinsfile
以下是可在 Jenkinsfile 中使用的示例代码片段

    post {
        success {
            jacoco(
                execPattern: '**/build/jacoco/*.exec',
                classPattern: '**/build/classes/java/main',
                sourcePattern: '**/src/main'
            )
        }
    }

See https://www.jenkins.io/doc/pipeline/steps/jacoco/ for the list of available options.
有关可用选项的列表,请参阅 https://www.jenkins.io/doc/pipeline/steps/jacoco/。

Looking for ways to contribute?
正在寻找贡献方式?

When looking for things to work at there are pull requests and a list of Jenkins Issues.
当寻找可以解决的问题时,有拉取请求和 Jenkins 问题列表。

In general the plugin is currently in "minimal maintenance" mode, i.e. no larger development is done due to the small number of active contributors and general time constraints.
一般来说,该插件目前处于“最小维护”模式,即由于活跃贡献者数量较少和一般时间限制,没有进行更大的开发。

Please speak up if you are interested in helping to maintain this plugin!
如果您有兴趣帮助维护这个插件,请大声说出来!

Discussion list 讨论列表

There is a developer list at https://groups.google.com/forum/#!forum/jenkins-jacoco-plugin-mailing-list, it is usually very low volume.
https://groups.google.com/forum/#!forum/jenkins-jacoco-plugin-mailing-list 有一个开发人员列表,通常数量很少。

Contributing to the Plugin
为插件做出贡献

Plugin source code is hosted on GitHub.
插件源代码托管在 GitHub 上。

New feature proposals and bug fix proposals should be submitted as GitHub pull requests.
新功能提案和错误修复提案应作为 GitHub 拉取请求提交。

Fork the repository on GitHub, prepare your change on your forked copy, and submit a pull request (see here for open pull requests). Your pull request will be evaluated by this job.
在 GitHub 上分叉存储库,在分叉副本上准备更改,然后提交拉取请求(请参阅此处了解开放的拉取请求)。您的拉取请求将由该作业进行评估。

Before submitting your change, please assure that you've added a test which verifies your change. There have been many developers involved in the jacoco plugin and there are many, many users who depend on the jacoco-plugin. Tests help us assure that we're delivering a reliable plugin, and that we've communicated our intent to other developers in a way that they can detect when they run tests.
在提交更改之前,请确保您已添加一个测试来验证您的更改。已经有很多开发者参与了 jacoco 插件,并且有很多很多用户依赖 jacoco-plugin。测试帮助我们确保我们正在提供可靠的插件,并且我们已经以其他开发人员可以在运行测试时检测到的方式将我们的意图传达给他们。

Code coverage reporting is available as a maven target and is actively monitored. Please try your best to improve code coverage with tests when you submit.
代码覆盖率报告可作为 Maven 目标使用,并受到积极监控。请在提交时尽力通过测试提高代码覆盖率。

Before submitting your change, please review the output of the checks that run in CI at https://ci.jenkins.io/job/Plugins/job/jacoco-plugin/ to assure that you haven't introduced new warnings.
在提交更改之前,请检查在 CI 中运行的检查的输出(网址为 https://ci.jenkins.io/job/Plugins/job/jacoco-plugin/),以确保您没有引入新的警告。

How to build and test
如何构建和测试

  • Build the plugin: 构建插件:

mvn package

  • Test locally (invokes a local Jenkins instance with the plugin installed):
    本地测试(调用安装了插件的本地 Jenkins 实例):

mvn hpi:run

See https://jenkinsci.github.io/maven-hpi-plugin/ for details.
有关详细信息,请参阅 https://jenkinsci.github.io/maven-hpi-plugin/。

How to release a new version
如何发布新版本

Rolling a release requires you to set up a few additional things:
滚动发布需要您设置一些额外的东西:

  • Run with Java 11 to not push code compiled with a newer version of Java
    使用 Java 11 运行,不推送使用较新版本的 Java 编译的代码

  • Github authentication should work via SSH, username used should be "git", it should use one of the local private SSH keys which should be uploaded to Github, see https://github.com/settings/keys, test via
    Github 身份验证应通过 SSH 进行,使用的用户名应为“git”,它应使用应上传到 Github 的本地 SSH 私钥之一,请参阅 https://github.com/settings/keys,通过进行测试

    ssh -T git@github.com

You should get back a line containing You've successfully authenticated
您应该返回包含 You've successfully authenticated 的行

  • Jenkins-CI authentication should work via settings in ~/.m2/settings.xml, see http://maven.apache.org/guides/mini/guide-encryption.html for details
    Jenkins-CI 身份验证应通过 ~/.m2/settings.xml 中的设置进行工作,有关详细信息,请参阅 http://maven.apache.org/guides/mini/guide-encryption.html

  • The mvn-calls below should not require "username" or "password", if they do ask for it, then some setup is incorrect
    下面的 mvn 调用不应要求“用户名”或“密码”,如果他们确实要求,则某些设置不正确

  • Apache Maven 3.8.1 or newer is required
    需要 Apache Maven 3.8.1 或更高版本

  • Check that all tests pass ("mvn findbugs:check" and "mvn checkstyle::check" report violations but are not blocking releases for now...)
    检查所有测试是否通过(“mvn findbugs:check”和“mvn checkstyle::check”报告违规,但目前不阻止发布......)

    mvn clean package && mvn validate

  • Manually test the plugin
    手动测试插件

    mvn hpi:run

    Go to http://localhost:8080/jenkins/ and perform some testing
    转到 http://localhost:8080/jenkins/ 并执行一些测试

  • Prepare the release 准备发布

    mvn release:prepare -DskipTests -Dmaven.test.skip=true

    This will ask for the release numbers and the tag in the source control system.
    这将要求提供版本号和源代码控制系统中的标签。

  • Roll the release 滚动发布

    mvn release:perform -DskipTests -Darguments="-DskipTests" -Dmaven.test.skip=true

    This should perform the actual uploads of the resulting binary packages.
    这应该执行生成的二进制包的实际上传。

  • Update release notes at https://github.com/jenkinsci/jacoco-plugin/tags
    更新发行说明:https://github.com/jenkinsci/jacoco-plugin/tags

  • Release should be visible immediately at https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/jacoco/
    发布应立即可见 https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/jacoco/

  • Release is published after some time at https://mvnrepository.com/artifact/org.jenkins-ci.plugins/jacoco?repo=jenkins-releases
    一段时间后发布在 https://mvnrepository.com/artifact/org.jenkins-ci.plugins/jacoco?repo=jenkins-releases

See also general documentation about releasing Jenkins plugins:
另请参阅有关发布 Jenkins 插件的一般文档:

Basic information 基本信息

This plugin allows you to capture code coverage report from JaCoCo. Jenkins will generate the trend report of coverage and some other statistics.
该插件允许您从 JaCoCo 捕获代码覆盖率报告。 Jenkins 将生成覆盖率趋势报告和一些其他统计数据。

It also includes functionality to include columns in Dashboards which displays the latest overall coverage numbers and links to the coverage report.
它还包括在仪表板中包含列的功能,其中显示最新的总体覆盖率数字和覆盖率报告的链接。

Getting Started 入门

The plugin provides two things, a build-publisher to record and display coverage data as part of builds as well as a new column-type for dashboard views which can display coverage data in Dashboards.
该插件提供了两个功能,一个是构建发布器,用于在构建过程中记录和显示覆盖率数据,另一个是仪表板视图的新列类型,可以在仪表板中显示覆盖率数据。

Recording coverage for builds
记录构建的覆盖范围

Get coverage data as part of your build
获取覆盖率数据作为构建的一部分

First you need to get coverage calculated as part of your build/tests, see the JaCoCo documentation
首先,您需要将覆盖率计算为构建/测试的一部分,请参阅 JaCoCo 文档

for details. You need at least one or more *.exec file available after tests are executed. Usually this means adjusting
了解详情。执行测试后,您至少需要一个或多个可用的 *.exec 文件。通常这意味着调整

your Maven pom.xml or Ant build.xml file..
你的 Maven pom.xml 或 Ant build.xml 文件..

Set up coverage retrieval and publishing
设置报道检索和发布

In order to get the coverage data published to Jenkins, you need to add a JaCoCo publisher and configure it so it will
为了将覆盖率数据发布到 Jenkins,您需要添加一个 JaCoCo 发布者并对其进行配置,以便它将

find all the necessary information. Use the help provided via the question-mark links for more information. Basically
找到所有必要的信息。使用通过问号链接提供的帮助来获取更多信息。基本上

you specify where the *.exec files are, where compiled code can be found and where the corresponding source code is
您指定 *.exec 文件的位置、编译后的代码在哪里以及相应的源代码在哪里

located after the build is finished to let the plugin gather all necessary pieces of information..
位于构建完成后,让插件收集所有必要的信息。

Run the job 运行作业

After the job executed, the build-output will show that the JaCoCo-publisher is executed and collects the data. This
作业执行后,构建输出将显示 JaCoCo-publisher 已执行并收集数据。这

output can also give hints if something goes wrong at this stage:
如果此阶段出现问题,输出还可以给出提示:

Zeichne Testergebnisse auf.
[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] build/*.exec;build/*-classes;src/java,src/*/java,src/*/src; locations are configured
[JaCoCo plugin] Number of found exec files: 5
[JaCoCo plugin] Saving matched execfiles:  .../build/jacoco-excelant.exec .../build/jacoco-main.exec .../build/jacoco-ooxml-lite.exec
[JaCoCo plugin] Saving matched class directories:  .../build/examples-classes .../build/excelant-classes .../build/excelant-test-classes
[JaCoCo plugin] Saving matched source directories:  .../src/contrib/src .../src/examples/src .../src/excelant/java .../src/java
[JaCoCo plugin] Loading inclusions files..
[JaCoCo plugin] inclusions: []
[JaCoCo plugin] exclusions: [**/Test*]
[JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=0, minMethod=0, maxMethod=0, minLine=0, maxLine=0,
minBranch=0, maxBranch=0, minInstruction=0, maxInstruction=0, minComplexity=0, maxComplexity=0]
[JaCoCo plugin] Publishing the results..
[JaCoCo plugin] Loading packages..
[JaCoCo plugin] Done.
Look at results 看结果

If data gathering is successful, the build will include a link to the coverage results similar to the HTML report of
如果数据收集成功,构建将包含一个指向覆盖结果的链接,类似于 HTML 报告

JaCoCo itself. The job page will be enhanced with a chart with the trend of code coverage over the last builds.
贾可可本身。作业页面将通过包含上次构建的代码覆盖率趋势的图表得到增强。

Coverage column 覆盖栏目

This part of the JaCoCo plugin allows you to add a new type of column to a project-table in the Dashboard view which
JaCoCo 插件的这一部分允许您向仪表板视图中的项目表添加新类型的列,

will show the coverage number of the last build for ajob together with some color coding which allows to quickly see
将显示作业的最后构建的覆盖率编号以及一些颜色编码,以便快速查看

projects with low coverage.
覆盖率低的项目。

The fill-color in use by the column is a continuous color-range with the following points:
列使用的填充颜色是一个连续的颜色范围,具有以下几点:

  • PERFECT = 100.0 完美 = 100.0
  • EXCELLENT at 97.0 优秀,97.0
  • GOOD at 92.0 良好,92.0
  • SUFFICIENT at 85.0 85.0 就足够了
  • FAIR at 75.0 公平为 75.0
  • POOR at 50.0 50.0 较差
  • TRAGIC at 25.0 悲剧性的 25.0
  • ABYSSMAL at 0.0 0.0 深渊
  • NA = No coverage configured
    NA = 未配置覆盖范围

Open Tickets (bugs and feature requests)
开放票证(错误和功能请求)

See the Jenkins JIRA 查看 Jenkins JIRA

Build Status 构建状态


Troubleshooting 故障排除

  • Unfortunately JaCoCo 0.7.5 breaks compatibility to previous binary formats of the jacoco.exec files. The JaCoCo plugin up to version 1.0.19 is based on JaCoCo 0.7.4, thus you cannot use this version with projects which already use JaCoCo 0.7.5 or newer. JaCoCo plugin starting with version 2.0.0 uses JaCoCo 0.7.5 and thus requires also this version to be used in your projects. Please stick to JaCoCo plugin 1.0.19 or lower if you still use JaCoCo 0.7.4 or lower
    不幸的是,JaCoCo 0.7.5 破坏了与 jacoco.exec 文件以前的二进制格式的兼容性。 JaCoCo 插件至版本 1.0.19 基于 JaCoCo 0.7.4,因此您不能将此版本用于已使用 JaCoCo 0.7.5 或更高版本的项目。从版本 2.0.0 开始的 JaCoCo 插件使用 JaCoCo 0.7.5,因此也需要在您的项目中使用此版本。如果您仍然使用 JaCoCo 0.7.4 或更低版本,请坚持使用 JaCoCo 插件 1.0.19 或更低版本

Change Log 变更日志

For current versions see the changelog in the release-area at https://github.com/jenkinsci/jacoco-plugin/releases
对于当前版本,请参阅发布区域中的变更日志:https://github.com/jenkinsci/jacoco-plugin/releases

Historic Change Log 历史变更日志

Version 2.0.1 (Jan 15, 2016)
版本 2.0.1(2016 年 1 月 15 日)

  • Fix the m2e lifecycle-mapping, #64
    修复 m2e 生命周期映射,#64
  • Integrate automated builds via travis-ci and show the build-state on the github page
    通过 travis-ci 集成自动化构建并在 github 页面上显示构建状态
  • Fix for JENKINS-31751 JaCoCo 2.0.0 plugin shows html instead of coverage report chart
    修复 JENKINS-31751 JaCoCo 2.0.0 插件显示 html 而不是覆盖率报告图表

Version 2.0.0 (Nov 23, 2015)
版本 2.0.0(2015 年 11 月 23 日)

  • Major version change because the jacoco.exec file from the newer JaCoCo is binary incompatible with previous builds
    主要版本更改,因为较新的 JaCoCo 中的 jacoco.exec 文件与以前的版本二进制不兼容
  • Update to JaCoCo 0.7.5, this causes binary incompatibility! See #55
    更新到 JaCoCo 0.7.5,这会导致二进制不兼容!参见#55
  • Add coverage summary on build status/result page. Thanks to Felipe Brandão for the patch, see #61
    在构建状态/结果页面上添加覆盖率摘要。感谢 Felipe Brandão 提供的补丁,请参阅 #61

Version 1.0.19 (Apr 7, 2015)
版本 1.0.19(2015 年 4 月 7 日)

  • Update used version of JaCoCo to 0.7.4
    将使用的JaCoCo版本更新至0.7.4

Version 1.0.18 (Dec 7, 2014)
版本 1.0.18(2014 年 12 月 7 日)

  • Fix JENKINS-23708 NullPointerException if older JaCoCo reports are opened
    如果打开较旧的 JaCoCo 报告,请修复 JENKINS-23708 NullPointerException

Version 1.0.17 (Nov 25, 2014)
版本 1.0.17(2014 年 11 月 25 日)

Version 1.0.16 (Jun 24, 2014)
版本 1.0.16(2014 年 6 月 24 日)

Version 1.0.15 (Jun 11, 2014)
版本 1.0.15(2014 年 6 月 11 日)

Version 1.0.14 (Nov 9, 2013)
版本 1.0.14(2013 年 11 月 9 日)

Core JaCoCo plugin 核心 JaCoCo 插件

Version 1.0.13 (Aug 22, 2013)
版本 1.0.13(2013 年 8 月 22 日)

Core JaCoCo plugin 核心 JaCoCo 插件

Coverage column: 覆盖栏:

Version 1.0.12 (Feb 22, 2013)
版本 1.0.12(2013 年 2 月 22 日)

Version 1.0.11 (Feb 21, 2013)
版本 1.0.11(2013 年 2 月 21 日)

Version 1.0.10 (Feb 05, 2013)
版本 1.0.10(2013 年 2 月 5 日)

Version 1.0.9 (Nov 18, 2012)
版本 1.0.9(2012 年 11 月 18 日)

Version 1.0.8 (Okt 15, 2012)
版本1.0.8(2012年10月15日)

Version 1.0.7 (Okt 8, 2012)
版本1.0.7(2012年10月8日)

Version 1.0.6 (Okt 2, 2012)
版本1.0.6(2012年10月2日)

Version 1.0.5 (Sep 09, 2012)
版本 1.0.5(2012 年 9 月 9 日)

  • Fixed JENKINS-15088: When the missed count is bigger than the covered, the redbar becomes too long
    修复了 JENKINS-15088:当错过的计数大于覆盖的计数时,红条变得太长

Version 1.0.4 (Sep 03, 2012)
版本 1.0.4(2012 年 9 月 3 日)

  • Fixed JENKINS-14896: java.io.FileNotFoundException when saving module data
    修复了 JENKINS-14896:保存模块数据时出现 java.io.FileNotFoundException

Version 1.0.3 (Aug 20, 2012)
版本 1.0.3(2012 年 8 月 20 日)

  • New concept implemented JENKINS-14927: Use the EXEC files instead the XMLs
    实施的新概念 JENKINS-14927:使用 EXEC 文件而不是 XML
  • Fixed JENKINS-14279: Report "missed items" rather that coverage percentage
    修复了 JENKINS-14279:报告“丢失的项目”而不是覆盖率
  • Fixed JENKINS-14159: 404 when trying to see coverage on java code (implementation of sourcefile highlighting)
    修复了 JENKINS-14159:尝试查看 Java 代码的覆盖范围时出现 404(源文件突出显示的实现)
  • New feature JENKINS-14274: Multi module reporting
    新功能 JENKINS-14274:多模块报告

Version 1.0.2 (Jul 01, 2012)
版本 1.0.2(2012 年 7 月 1 日)

  • Fixed JENKINS-14270: The report does not show the covered/all, it shows something different
    修复了 JENKINS-14270:报告不显示覆盖/全部,它显示不同的内容

Version 1.0.1 (Jun 25, 2012)
版本 1.0.1(2012 年 6 月 25 日)

  • Fixed testcases to have all the tests passed for a release
    修复了测试用例以通过发布的所有测试
  • Fixed JENKINS-14203: The total summary is double counted
    修复了 JENKINS-14203:总摘要被重复计算

Version 1.0.0 (Jun 14, 2012)
版本 1.0.0(2012 年 6 月 14 日)

  • Fixed 3 testcases to have all the tests passed for a release
    修复了 3 个测试用例以使所有测试都通过发布
  • Fixed POM: making it releasabl
    修复 POM:使其可发布