At the moment Clover allows to exclude code from coverage measurement using five methods:
excluding entire file
- in Ant it is <clover-setup> / <fileset> / <excludes> tag
- in Maven it is <excludes>, <excludesFile> or <excludesList> option
excluding certain methods
- in Ant it is <clover-setup> / <methodContext> tag combined with the <clover-report> / <current> / <
- in Maven it is not available directly - you'd have to use the <reportDescriptor> option to configure report format in an external XML file; the problem is with clover-setup which you'd also have to customise - maybe calling the Clover via maven-antrun-plugin could help here
excluding certain statements
- in Ant it is <clover-setup> / <statementContext> tag combined with the <clover-report> / <current> / <
- in Maven you'd have to use the <reportDescriptor>
excluding certain code blocks
- in Ant it is <clover-report> / <current> / < with a predefined names of blocks, e.g. 'constructor' or 'switch' - see Using+Coverage+Contexts for more details
- in Maven you'd have to use the <reportDescriptor>
excluding arbitrary source lines
You can put //CLOVER:OFF and //CLOVER:ON inline comments in the source code
Unfortunately, at the moment it's not possible to exclude the given class. However, I can see few workarounds available:
Add the //CLOVER:OFF and //CLOVER:ON comments around classes you want to exclude.
Exclude entire files
Treat these @Configuration classes as test code.
This is a hack. Clover allows to declare which classes are test classes. The match is based on file name, class signature and test signature. See the <clover-setup> / <testsources> / <testclass> tag. In this testclass tag you can define a regular expression matching entire class signature. In your case it could be:
<testclass annotation=".*@Configuration.*"/>
While this will not disable code instrumentation for these classes, they would be treated as test code and they should not contribute to application code metrics.
Note that Clover calculates code metrics for application and test code separately.
References: