JaCoCo Code Coverage Without Touching pom.xml

No configuration needed inside pom.xml. Run this single command:

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test org.jacoco:jacoco-maven-plugin:report

How it works:

  1. org.jacoco:jacoco-maven-plugin:prepare-agent: Adds the JaCoCo agent to the JVM that runs the tests
  2. test: Runs tests as usual
  3. org.jacoco:jacoco-maven-plugin:report: Generates the HTML report

The report is generated in target/site/jacoco. To view it:

python3 -m http.server -d target/site/jacoco 8181

Then open http://localhost:8181.

Note: This approach works because of Maven’s plugin-based architecture. Plugins can be invoked directly without any permanent configuration.