Advanced report configuration

Define a reporttask closure in your clover {} code block to configure advanced report generation options for your Groovy project's build process. Here, you can define various attributes and elements of the clover-report task. In fact, any Clover Ant tasks and their attributes and elements may be used in this closure.

(info) You would not normally include clover-setup tasks in the reporttask closure because the latter is executed after the clover-setup tasks have executed.

The reporttask closure is passed the following parameters:

  • ant — an instance of a org.codehaus.gant.GantBuilder
  • binding — the groovy binding for accessing project variables
  • plugin — the clover grails plugin that invoked this closure

The syntax used to define your clover-report tasks or any other valid Ant task in the clover {} code block is Gant.

 

Example: custom reports in PDF, HTML, XML and JSON formats

The following example clover {} code block and reporttask definition in your BuildConfig.groovy file will:

  • generate a Clover report in both PDF and HTML formats and
  • place the results in the build/clover/report subdirectory of your Grails project directory.
clover {

  // reports.dir defines the location of your Clover report output
  // within your Grails project.

  reports.dir = "build/clover/report"

  // The reporttask closure is invoked after all tests have run.

  reporttask = { ant, binding, plugin ->

    ant.mkdir(dir: "${clover.reports.dir}")

    ant.'clover-report' {

      ant.current(outfile: "${clover.reports.dir}/clover.pdf", summary: true) {
        format(type: "pdf")
      }

      ant.current(outfile: "${clover.reports.dir}") {
        format(type: "html")
        ant.columns {
          lineCount()
          complexity()
          filteredElements(format:"bar")
          uncoveredElements(format: "raw")
          totalElements(format: "raw")
          totalPercentageCovered()
        }
      }

      ant.current(outfile: "${clover.reports.dir}/clover.xml") {
        format(type: "xml")
      }

      ant.current(outfile: "${clover.reports.dir}") {
        format(type: "json")
      }

   }

   plugin.launchReport(clover.reports.dir)

}

 

The reporttask closure could be also used to run other post-build activities, like clover-check or clover-log, for example.

Example: failing build if code coverage is too low

reporttask = { ant, binding, self ->
      ant.'clover-check'(target: "80%", haltOnFailure: true) { }
}
Last modified on Jan 16, 2017

Was this helpful?

Yes
No
Provide feedback about this article

Not finding the help you need?

Ask the community

Powered by Confluence and Scroll Viewport.