1

I want to run JaCoCo from the command line on a Maven project without including JaCoCo configuration into the pom.xml.

How do I configure and invoke JaCoCo from the command line like:

$ mvn test <JaCoCo - config params>

In essence, I am looking to get a coverage report for a Maven project without having to manually edit its pom.xml. Invoking JaCoCo directly on the Maven project (without invoking the mvn command would work to.

ragnacode
  • 332
  • 3
  • 13
  • You should at least configure the version into your pom file and afterwards calling is easier from command. I don't understand why you don't want to configure that in your pom file??? – khmarbaise May 17 '22 at 17:23
  • @khmarbaise Because I want to run it on a large number of Maven projects that I do not own, and I am seeking a solution that has low overhead and that does not require configuration changes that may create errors or interfere with the well-functioning of the project in any way. – ragnacode May 17 '22 at 17:37

2 Answers2

1

You can use:

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

to call jacoco generation directly from command line without any change in your pom file.

You can replace verify by test

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
0

JaCoCo works by instrumenting the virtual machine before tests are run. Normally one configures the Surefire plugin to include some additional args and use a JVM agent, or to rewrite the byte code of the classes to do something equivalent.

I would check this answer: How to configure JaCoCo maven plugin from command line

Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84
  • Does this not require me to actually include the JaCoCo plugin in the pom.xml such that I can invoke the plugin on the command line? If so, is there no option to tell maven on the command line, to include a plugin on-demand? I know that I can configure the Surefire plugin from the command line. – ragnacode May 17 '22 at 17:39
  • Take a look at the answers in the linked question! – Jonathan S. Fisher May 17 '22 at 17:42
  • I did read that question, in fact I did read it before you recommended it to me. The issue is that I did not recognize the answer to my question in it and I am not sure the use case is similar to mine. To me, that post reads as if the JaCoCo plugin could be set up already in the pom.xml and only *some* configuration is done on-demand from the command line. So, for me, it does not answer the question, can I run JaCoCo without any plugin configuration in the pom.xml whatsoever and will it work on multimodule projects as well? Hope I make sense, I wish I knew more about Maven. – ragnacode May 17 '22 at 17:53