问题
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.
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
?
回答1:
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>
then, on the command-line, having
-Dcobertura.instrumentation.exclude=com/example/dullcode/**/*.class
will correctly exclude those classes. And if you don't specify the system property, nothing will be excluded.
来源:https://stackoverflow.com/questions/40023283/how-to-define-complex-maven-properties-in-the-comand-line