如何在命令行中定义复杂的Maven属性 [英] How to define complex Maven properties in the comand line
问题描述
我正在使用Maven cobertura插件进行检索我的单元测试代码涵盖了这一点,我正在通过命令行使用它:
I'm using the Maven cobertura plugin to retrieve my unit test code covering and I'm using it through the command line:
mvn cobertura:cobertura
我想做的是从命令行配置排除项.如您从官方文档中看到的,我们可以配置一个 仪器用户属性.
What I would like to do is configure the exclusions from command line. As you can see from the official documentation, we can configure an instrumentation user property.
此Instrumentation Configuration对象具有以下结构:
This Instrumentation Configuration object has the below structure:
<instrumentation>
<excludes>
<exclude>com/example/dullcode/**/*.class</exclude>
</excludes>
</instrumentation>
有什么方法可以仅使用命令行形式的类似上述配置复杂对象
Is there any way to configure a complex object like the above using only the command line in the form of
-Dcobertura.instrumentation.excludes.<something>=com/example/dullcode/**/*.class
?
推荐答案
否,您不能在命令行上定义一个复杂的参数.但是,您可以实施一个技巧来实现此目的:定义一个在命令行中覆盖的Maven属性.
No, you can't define a complex parameter on the command line. But you can implement a trick to make this work: define a Maven property that you override on the command-line.
您可以使用以下方式配置插件:
You can configure the plugin with:
<instrumentation>
<excludes>
<exclude>${cobertura.instrumentation.exclude}</exclude>
</excludes>
</instrumentation>
然后在命令行上具有
-Dcobertura.instrumentation.exclude=com/example/dullcode/**/*.class
将正确排除那些类.而且,如果您未指定system属性,则不会排除任何内容.
will correctly exclude those classes. And if you don't specify the system property, nothing will be excluded.
这篇关于如何在命令行中定义复杂的Maven属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!