reference
Questions from the top of my head since that time I went crazy with jacoco.
My application server (jBoss, Glassfish ..), located in Iraq, Syria, whatever it is. Is it possible to get multi-module coverage when performing integration tests? Jenkins and Sonar are also located on different servers.
Yes. You should use jacoco agent , which works in output=tcpserver mode, jacoco ant lib. Basically two jar s. This will give you 99% success.
How does jacoco agent work?
You add line
-javaagent:[your_path]/jacocoagent.jar=destfile=/jacoco.exec,output=tcpserver,address=*
to your JAVA_OPTS application server and reload it. In this line, only [your_path] needs to be replaced with the path to jacocoagent.jar, save (save it!) On your virtual machine where the application server is running. From this moment you start the application server, all applications that will be deployed will be dynamically controlled, and their activity (the meaning of using the code) will be ready for you in jacocos.exec format at the request of tcl.
Can I reset the jacoco agent to start collecting execution data only from the moment the test starts?
Yes, for this purpose you need jacocoant.jar and ant build script located in the jenkins workspace.
So basically what I need from http://www.eclemma.org/jacoco/ is jacocoant.jar located in my jenkins workspace and jacocoagent.jar located on my VM application server?
It is right.
I do not want to use ant, I heard that the jacoco maven plugin can do everything too.
Wrong, the jacoco maven plugin can collect unit test data and some integration test data (see Arquillian Jacoco ), but if you have, for example, saving completed tests as split assemblies in jenkins and want to show multi-module coverage, I donβt see how it can help maven plugin.
What exactly does the jacoco agent produce?
Only coverage data in .exec format. Then the sonar can read it.
Do jacoco need to know where my java classes are?
No, sonar does, but not jacoco. When you do mvn sonar:sonar , the class path comes into play.
So what about ant script?
It should be presented in the jenkins workspace. Mine ant script, I called it jacoco.xml looks like this:
<project name="Jacoco library to collect code coverage remotely" xmlns:jacoco="antlib:org.jacoco.ant"> <property name="jacoco.port" value="6300"/> <property name="jacocoReportFile" location="${workspace}/it-jacoco.exec"/> <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml"> <classpath path="${workspace}/tools/jacoco/jacocoant.jar"/> </taskdef> <target name="jacocoReport"> <jacoco:dump address="${jacoco.host}" port="${jacoco.port}" dump="true" reset="true" destfile="${jacocoReportFile}" append="false"/> </target> <target name="jacocoReset"> <jacoco:dump address="${jacoco.host}" port="${jacoco.port}" reset="true" destfile="${jacocoReportFile}" append="false"/> <delete file="${jacocoReportFile}"/> </target> </project>
Two required parameters that you must pass when calling script -Dworkspace=$WORKSPACE use it to point to the jenkins workspace and -Djacoco.host=yourappserver.com host without http://
Also note that I put my jacocoant.jar in $ {workspace} /tools/jacoco/jacocoant.jar
What should I do next?
Have you started your application server using jacocoagent.jar?
Have you put ant script and jacocoant.jar in your jenkins workspace?
If so, the last step is to configure the jenkins build. Here is the strategy:
- Call ant target
jacocoReset to reset all previously collected data. - Run tests
- Call ant target
jacocoReport to get a report
If everything is correct, you will see it-jacoco.exec in the assembly workspace.
Look at the screenshot, I also have ant installed in my workspace in the $WORKSPACE/tools/ant directory, but you can use the one installed in your jenkins.

How to move this report to sonar?
Maven sonar:sonar will complete the task (do not forget to configure it), point it to the main pom.xml so that it runs through all modules. Use the sonar.jacoco.itReportPath=$WORKSPACE/it-jacoco.exec to tell the sonar where your integration report is located. Each time he analyzes new classes of modules, he will look for coverage information in it-jacoco.exec .
I already have jacoco.exec in my `target` directory,` mvn sonar: sonar` ignores / removes it
By default, mvn sonar:sonar runs clean and removes your target directory, use sonar.dynamicAnalysis=reuseReports to avoid it.