Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Jenkins Clover Plugin 4.10.0

...

Wiki Markup
{jenkins-plugin-info:pluginId=clover}
Excerpt

This plugin allows you to capture code coverage reports from OpenClover - a free and open source tool based on source code of Atlassian Clover. Jenkins will generate and track code coverage across time. This plugin can be used without the need to modify your build.xml.

Installation

  1. Install Jenkins Clover Plugin.
  2. Install clover.jar in Ant's classpath (since Jenkins Clover Plugin 4.10.0).

Automatic integration for Ant builds

Section
Column

Since version 2.0 of the Clover Plugin, Clover can be integrated into Ant-based builds without the need to modify the build.xml (star) . Simply check the "Automatically record and report Code Coverage" checkbox in the Job configuration screen.

The Clover plugin will add an Ant build listener and appropriate configuration parameters to allow Clover HTML, XML, JSON and Historical reports to be generated for your Job.

These will automatically be linked to from the Job and Build pages.

The Clover License string can be configured either per-Job, or globally view the "Manage Jenkins -> Configure System -> Manage Clover" screen.

Image Removed


(star) It works for typical build configurations in which unit tests are launched after compilation. In case you spawn processes, run in-container tests, deploy application to another machine etc then the automatic integration will not be sufficient and you'll have to set up integration manually.

Column

...

We recommend reading the official Clover OpenClover Documentation home page - you will find instructions how to integrate Clover with Ant, Maven, Grails and other tools.

In case of trouble, you may have a look at the Atlassian AnswersCommunity page (questions tagged 'clover').

...

  1. Install the Clover plugin
  2. Configure your project's build script to generate Clover XML reports
  3. Optional: Configure your project's build script to generate clover HTML or PDF reports (this plugin prefers HTML reports to PDF).  The plugin will not extract any information from these reports, but will use them as a better formatted most recent coverage report when they are available.
  4. Enable the "Publish Clover Coverage Report" publisher
  5. Specify the directory where the clover.xml report is generated.
  6. Optional: Configure the coverage metric targets to reflect your goals.

Configuring with Jenkins Workflow/Pipeline jobs

As of version 4.6.0 (and later) of the plugin:

Code Block

node {
  git 'https://github.com/recena/maven-helloworld'
  sh "mvn clean clover:setup test clover:aggregate clover:clover"
  step([
    $class: 'CloverPublisher',
    cloverReportDir: 'target/site',
    cloverReportFileName: 'clover.xml',
    healthyTarget: [methodCoverage: 70, conditionalCoverage: 80, statementCoverage: 80], // optional, default is: method=70, conditional=80, statement=80
    unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50], // optional, default is none
    failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0]     // optional, default is none
  ])
}

...

  • Create the job as a "free-style software project".
  • Enable the "Invoke top-level Maven targets" Build.
  • Specify the following goals for Maven: (Note the use of the pipe character | to invoke maven three times).
Code Block

install
-Dmaven.test.failure.ignore=true
|
-Dclover.license.file=path-to-clover-license
clover:instrument
clover:aggregate
|
-Dclover.license.file=path-to-clover-license
-N
clover:aggregate
clover:clover
  • Enable the "Publish Clover Coverage Report" publisher.
  • Depending on your Source Code Management, the clover report directory will either be "target/site/clover" or "module-name/target/site/clover"
  • Don't forget to configure the pom.xml to generate the clover.xml report

    Code Block
    
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      ...
      <build>
        ...
        <plugins>
    
         ...       <plugin>
            <groupId>com.atlassian.maven.plugins<<groupId>org.openclover</groupId>
            <artifactId>clover-maven-plugin</artifactId>
            ...
    	<configuration>
              ...
              <licenseLocation>${clover.license.file}</licenseLocation>  <generateHtml>true</generateHtml>
              <generateHtml>true</generateHtml>           <generateXml>true</generateXml>
              ...
            </configuration>
            ...
          </plugin>
    
     
        ...
        </plugins>
        ...
      </build>
      ...
    </project>
    

Maven2, Clover and Multimodule with a <packaging>ear</packaging> child module

...

To work around this, you should configure your root pom to include the <packaging>ear</packaging> targets only when you are not using clover... how to do this:

Code Block

<project>
  ...
  <profiles>
    ...
    <profile>
      <id>running-clover</id>
      <activation><build>
        <property><pluginManagement>
          <name>clover.license.file</name><plugins>
        </property>    <plugin>
  </activation>       <build>     <groupId>org.openclover</groupId>
   <pluginManagement>           <plugins>
            <plugin>
              <artifactId>clover-maven-plugin</artifactId>
              <configuration>
                <licenseLocation>${clover.license.file}</licenseLocation>
                <generateHtml>true</generateHtml>
                <generateXml>true</generateXml>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>
    <profile>
      <id>not-running-clover</id>
      <activation>
        <property>
          <name>!clover.license.file</name>
        </property>
      </activation>
      <modules>
        <module>my-ear-artifact</module>
        <!-- list any other ear child modules here -->
      </modules>
    </profile>
    ...
  </profiles>
  ...
</project>

 The The above... hack... is why it is recommended to invoke maven three times.  If you don't need this hack, you could simplify down to two invocations and specify the clover license file location in the pom.xml, i.e.

install clover:instrument | -N clover:aggregate cloveclover:site

Version history

Version 4.10.0 (September 22, 2018)

  • Upgrade to OpenClover 4.3.1, which brings support for Java 9
  • Upgrade notes: you have to install clover.jar in Ant's classpath if you want to use automatic integration in Ant builds. See OpenClover 4.3.0 release notes for more details.


Version 4.9.0 (March 6, 2018)

  • Fixed bugs:
    • JENKINS-33610 - fixed IOException when running Clover on remote agents (it was impossible to run Clover on them)
    • JENKINS-34439 - solved various exceptions thrown when running Clover in pipieline builds
    • JENKINS-45981 - removed empty 'Manage Clover' section in global config
    • fixed automatic Clover integration not working on Windows on newer Jenkins versions (a change in how "cmd.exe /C ant.bat" is ran caused that Clover was not appending it's parameters to the command); also added additional logging
    • automatic integration does not attempt to auto-integrate with non-Ant tasks in the project (checks for presence of "ant.bat" or "ant" in the command)
  • Refreshed look&feel of the 'OpenClover summary report' page
  • Minimum Jenkins version is 1.642.3 (upgraded dependency on Wokflow Plugin to 2.0 - aka Pipelines Plugin)


Version 4.8.0 (June 8, 2017)

  • Plugin uses OpenClover - a free and open source fork of Atlassian Clover (which is no longer developed by Atlassian, see this blog post)
  • You no longer need a license key to run Clover (smile)


Version 4.7.1 (December 19, 2016)

...