问题
In a parent POM we have Jacoco rules set up to enforce test coverage. This includes some exclusions for classes that typically don't have behavior:
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<excludes>
<!-- exclude largely auto-generated domain and model classes -->
<exclude>**/model/*.class</exclude>
<exclude>**/model/**/*.class</exclude>
<exclude>**/domain/*.class</exclude>
<exclude>**/domain/**/*.class</exclude>
<exclude>**/dto/*.class</exclude>
<exclude>**/dto/**/*.class</exclude>
</excludes>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.70</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
In a child POM that uses this parent, what is the Maven magic for adding additional excluded class patterns?
I'm trying to use combine...
attributes in various ways but am unable to get the effective POM to come out correctly.
Any ideas?
回答1:
You can't extend the list but you can overwrite it. Most of the time, you'll want a specific list of exclusions per module (how often do you have the exact same types in different modules?)
To do that, don't put any exclusions in the parent POM. Just put the standard/shared executions and their configuration in there. In the child POM:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>ch/swissquant/toolbox/exceptions/**/*.class</exclude>
<exclude>ch.swissquant.toolbox.exceptions.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Maven will read this configuration and merge it with any execution it finds in the parent POM (so it will be applied to all steps of the complicated Jacoco process).
The merge works like this: Maven reads the parent POM and then overwrites it with any specific values from the child POM (last entry wins). This is also true for properties, so you can define default values for things like the coverage rations in the parent using properties and redefine the properties in the child.
You can verify this by running mvn help:effective-pom
.
来源:https://stackoverflow.com/questions/38085451/how-to-add-more-jacoco-exclusions-in-a-child-project