JaCoCo is able to record any kind of execution of Java application - you just need to start this application with agent, for example:
java -javaagent:jacoco-0.8.0/lib/jacocoagent.jar -cp classes Main
By default at termination of application this will produce file jacoco.exec
with execution data. There are also ways to get execution data from running application.
And there are plenty of examples all over the internet of using agent in various cases - with Spring Boot, Tomcat, Weblogic, etc.
After that report can be generated using this execution data jacoco.exec
and exactly the same class files that were used at runtime for generation of execution data. For example using JaCoCo command line interface (there are also Ant tasks, Gradle plugin, Maven plugin):
java -jar jacoco-0.8.0/lib/jacococli.jar
report
jacoco.exec
--classfiles classes
--html report
Report can be generated without source files, but in this case you won't be able to drill down lower than method level granularity:
Report with source files:
jacoco-0.8.0/lib/jacococli.jar
report
jacoco.exec
--classfiles classes
--html report
--sourcefiles src
Now about SonarQube: it performs analysis of exec
and class files, and so also requires that class files are the same as where used at runtime for generation of exec
file. So you need to guarantee that SonarQube analysis is performed for exactly the same class files as under testing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…