4

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

?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
gvdm
  • 3,006
  • 5
  • 35
  • 73

1 Answers1

4

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.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • 1
    As an addition, if you need multiple excludes, you could define multiple tags in the POM and use property names .exclude1, .exclude2 etc. Not very elegant, but does the trick. – Florian Albrecht Oct 13 '16 at 14:48
  • @Tunaki, thank you. Ok I got, but what if my project is a multi module project? I should configure the plugin only in one place, say the parent pom.xml, and exclude all test classes on all modules. Am I obliged to use `` in the parent and add on every module the plugin? – gvdm Oct 13 '16 at 15:01
  • 1
    @gvdm That is a different problem. Best practice would be to define the plugin inside `` of the parent, along with some default configuration, and let modules declare it when needed. – Tunaki Oct 13 '16 at 15:02