Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure JaCoCo maven plugin from command line

I'm trying to configure JaCoCo maven plugin from command line instead of using pom.xml. I have managed to execute prepare-agent so far with command:

mvn -X -Djacoco.destFile=./coverage/jacoco.exec clean org.jacoco:jacoco-maven-plugin:prepare-agent install

with output:

[DEBUG] Configuring mojo org.jacoco:jacoco-maven-plugin:0.7.6.201602180812:prepare-agent from plugin realm ClassRealm[plugin>org.jacoco:jacoco-maven-plugin:0.7.6.201602180812, parent: sun.misc.Launcher$AppClassLoader@70dea4e]
[DEBUG] Configuring mojo 'org.jacoco:jacoco-maven-plugin:0.7.6.201602180812:prepare-agent' with basic configurator -->
[DEBUG]   (f) destFile = /src/coverage/jacoco.exec
...

which creates ./coverage/jacoco.exec file and now I'm trying to run report stage but I am not able to set properties for this stage. I'm running command:

mvn -X -Djacoco.dataFile=./coverage/jacoco.exec -Djacoco.outputDirectory=./jacoco_ut org.jacoco:jacoco-maven-plugin:report

or

mvn -X -DdataFile=./coverage/jacoco.exec -DoutputDirectory=./jacoco_ut org.jacoco:jacoco-maven-plugin:report

as in jacoco:report there is no user property as in jacoco:prepare-agent.

i have output like:

[DEBUG] Configuring mojo 'org.jacoco:jacoco-maven-plugin:0.7.6.201602180812:report' with basic configurator -->
[DEBUG]   (f) dataFile = /src/target/jacoco.exec
[DEBUG]   (f) outputDirectory = /src/target/site/jacoco
[DEBUG]   (f) outputEncoding = UTF-8
[DEBUG]   (f) project = MavenProject: project:3.2.0-SNAPSHOT @ /src/pom.xml
[DEBUG]   (f) skip = false
[DEBUG]   (f) sourceEncoding = UTF-8
[DEBUG] -- end configuration --

with default values.

like image 608
widget Avatar asked Apr 20 '16 11:04

widget


1 Answers

Update to 0.7.8

The GitHub issue 322 has been resolved as of version 0.7.8 of the jacoco-maven-plugin. Starting from this version, you can use the user property jacoco.dataFile, so the commands in the question would work as-is.

To force the version on the command line, you should have:

mvn -Djacoco.destFile=./coverage/jacoco.exec clean org.jacoco:jacoco-maven-plugin:0.7.8:prepare-agent install

You can also configure the jacoco-maven-plugin inside your POM and specify this version explicitly.

Or keep the defaults

Before version 0.7.8, there is no user property for the dataFile attribute, so you won't be able to do that. You are correctly overriding the default value when you're invoking

mvn -Djacoco.destFile=./coverage/jacoco.exec clean org.jacoco:jacoco-maven-plugin:prepare-agent install

because jacoco.destFile is the name of the user property associated with the destFile attribute of the prepare-agent goal.

However, there are no user property for the corresponding dataFile attribute of the report goal. So your best bet would be to keep the default.

like image 70
Tunaki Avatar answered Sep 19 '22 05:09

Tunaki