本文介绍了如何从命令行配置JaCoCo Maven插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从使用pom.xml的命令行配置JaCoCo maven插件.到目前为止,我已经设法使用命令执行了prepare-agent:

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:

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

输出:

[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
...

创建./coverage/jacoco.exec文件,现在我试图运行report阶段,但是我无法为该阶段设置属性.我正在运行命令:

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

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

jacoco:report 一样,没有user property作为在 jacoco:prepare-agent 中.

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

我的输出如下:

[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 --

具有默认值.

推荐答案

更新为0.7.8

GitHub问题322 已从.从此版本开始,您可以使用用户属性jacoco.dataFile,因此问题中的命令将按原样工作.

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

您还可以在POM中配置jacoco-maven-plugin并明确指定此版本.

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

在版本0.7.8之前,没有用户属性作为dataFile属性,因此您将无法执行此操作.调用时,您正确地覆盖了默认值

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

因为 jacoco.destFile 是名称与prepare-agent目标的destFile属性相关联的用户属性.

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

但是,相应的 dataFile没有用户属性 report目标的属性.因此,最好的选择是保留默认值.

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.

这篇关于如何从命令行配置JaCoCo Maven插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:00
查看更多