I\'m trying to configure JaCoCo maven plugin from command line insted of using pom.xml
. I have managed to execute prepare-agent
so far with command
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.
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.
we use the below code:
mvn clean devtestcov:atest -Dactive.devtest -Dmaven.test.failure.ignore=true -Djacoco-agent.destfile=target/jacoco.exec
When You can not use property, you can use environment variable.
When I get Jacoco Diff Coverage jacoco:report includes cannot use property.
So I use ${inc_files}
Shell:
echo "+++git diff+++"
inc_files=`git diff --name-only master | grep -oP 'com/languoguang/xxclouds/quark.*.java' | xargs | sed 's/.java/.class/g' | xargs | sed -e 's/ /,/g'`;
echo ${inc_files};
echo "---git diff---";
echo "+++maven test jacoco+++";
mvn -B -f pom.xml -Dinc_files=${inc_files} clean test -Dmaven.test.failure.ignore=true;
echo "---maven test jacoco---";
pom.xml:
<execution>
<configuration>
<title>quark-frameworks-coverage-inc</title>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate/jacoco-aggregate-inc/</outputDirectory>
<includes>${inc_files}</includes>
</configuration>
<id>report-aggregate-inc</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
I hope this will be useful.