1<?xml version="1.0" encoding="UTF-8" ?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> 4<head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <link rel="stylesheet" href="resources/doc.css" charset="UTF-8" type="text/css" /> 7 <link rel="stylesheet" href="../coverage/jacoco-resources/prettify.css" charset="UTF-8" type="text/css" /> 8 <link rel="shortcut icon" href="resources/report.gif" type="image/gif" /> 9 <script type="text/javascript" src="../coverage/jacoco-resources/prettify.js"></script> 10 <title>JaCoCo - Maven Plug-in</title> 11</head> 12<body onload="prettyPrint()"> 13 14<div class="breadcrumb"> 15 <a href="../index.html" class="el_report">JaCoCo</a> > 16 <a href="index.html" class="el_group">Documentation</a> > 17 <span class="el_source">Maven Plug-in</span> 18</div> 19<div id="content"> 20 21<h1>Maven Plug-in</h1> 22 23<p> 24 The JaCoCo <a href="http://maven.apache.org/">Maven</a> plug-in provides the 25 JaCoCo runtime agent to your tests and allows basic report creation. 26</p> 27 28<p class="hint"> 29 If you want to have line number information included in the coverage reports 30 or you want source code highlighting the class files of the test target must 31 be compiled with debug information. 32</p> 33 34<p class="hint"> 35 When using the <tt>maven-surefire-plugin</tt> or <tt>maven-failsafe-plugin</tt> 36 you <b>must not</b> use a 37 <a href="http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#forkCount"> 38 <tt>forkCount</tt></a> of <tt>0</tt> or set the 39 <a href="http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#forkMode"> 40 <tt>forkMode</tt></a> to <tt>never</tt> as this would prevent the execution of 41 the tests with the <tt>javaagent</tt> set and no coverage would be recorded. 42</p> 43 44<h2>Example</h2> 45 46<ul> 47 <li> 48 The JaCoCo distribution contains a simple example how code coverage 49 can be added to a Maven project.</li> 50 <li> 51 This <a href="examples/build/pom.xml">POM file</a> 52 for a JAR project runs JUnit tests under code coverage and creates a coverage 53 report (<tt>target/site/jacoco/index.html</tt>). 54 </li> 55 <li> 56 This <a href="examples/build/pom-it.xml">POM file</a> 57 for a JAR project runs unit tests and integration tests under code coverage 58 and creates two coverage reports, one for unit tests ( 59 <tt>target/site/jacoco/index.html</tt>) and one for integration tests ( 60 <tt>target/site/jacoco-it/index.html</tt>). 61 </li> 62 <li> 63 The complete example is located in the <code>./doc/examples/build</code> 64 folder of the distribution. 65 </li> 66</ul> 67 68 69<h2>Prerequisites</h2> 70 71<p> 72 The JaCoCo Maven plug-in requires 73</p> 74 75<ul> 76 <li>Maven 2.1.0 or higher and</li> 77 <li>Java 1.5 or higher (for both, the Maven runtime and the test executor).</li> 78</ul> 79 80 81<h2>Usage</h2> 82 83<p> 84 The Maven plug-in can be included in your build with the following 85 declaration. Please check 86 <a href="http://search.maven.org/#search|ga|1|g%3Aorg.jacoco%20a%3Ajacoco-maven-plugin">here</a> 87 for the latest release version in the repository. 88</p> 89 90<pre class="source lang-xml linenums"> 91<plugin> 92 <groupId>org.jacoco</groupId> 93 <artifactId>jacoco-maven-plugin</artifactId> 94 <version>@project.version@</version> 95</plugin> 96</pre> 97 98<p> 99 To receive a full list of goals and available parameters you can use 100 <code>maven-help-plugin</code>: 101</p> 102<pre> 103mvn help:describe -Dplugin=org.jacoco:jacoco-maven-plugin -Ddetail 104</pre> 105 106<p> 107 Usage of plugin together with <tt>maven-site-plugin</tt> without 108 <a href="https://maven.apache.org/plugins/maven-site-plugin/examples/configuring-reports.html#Selecting_Reports_from_a_Plugin:_Configuring_Report_Sets">explicit selection of reports</a> 109 might lead to generation of redundant aggregate reports. 110 Specify <tt>reportSets</tt> explicitly to avoid this: 111</p> 112<pre class="source lang-xml linenums"> 113<project> 114 <reporting> 115 <plugins> 116 <plugin> 117 <groupId>org.jacoco</groupId> 118 <artifactId>jacoco-maven-plugin</artifactId> 119 <reportSets> 120 <reportSet> 121 <reports> 122 <!-- select non-aggregate reports --> 123 <report>report</report> 124 </reports> 125 </reportSet> 126 </reportSets> 127 </plugin> 128 </plugins> 129 </reporting> 130</project> 131</pre> 132 133<h2>Goals</h2> 134 135<p> 136 The JaCoCo Maven plug-in defines the following goals: 137</p> 138 139<ul> 140 <li><a href="help-mojo.html">help</a></li> 141 <li><a href="prepare-agent-mojo.html">prepare-agent</a></li> 142 <li><a href="prepare-agent-integration-mojo.html">prepare-agent-integration</a></li> 143 <li><a href="merge-mojo.html">merge</a></li> 144 <li><a href="report-mojo.html">report</a></li> 145 <li><a href="report-integration-mojo.html">report-integration</a></li> 146 <li><a href="report-aggregate-mojo.html">report-aggregate</a></li> 147 <li><a href="check-mojo.html">check</a></li> 148 <li><a href="dump-mojo.html">dump</a></li> 149 <li><a href="instrument-mojo.html">instrument</a></li> 150 <li><a href="restore-instrumented-classes-mojo.html">restore-instrumented-classes</a></li> 151</ul> 152 153</div> 154<div class="footer"> 155 <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span> 156 <a href="license.html">Copyright</a> © @copyright.years@ Mountainminds GmbH & Co. KG and Contributors 157</div> 158 159</body> 160</html> 161