Indeed this is a must-have on our site. We have big amounts of generated code which normally does not meet any rules. As these violations are reported the "real" problems are not really visible. As the code is generated via Maven (and placed in target/generated-sources) it should be easily possible for the sonar-plugin to detect them and auto-generate and apply the according exclusions.
Afaik sonar is only able to exclude based on package/classname patterns because PMD and other tools are working on bytecode. On the other hand which class is generated and which is not is not readable out of the bytecode (even if the @generated-annotation is used - it is not a runtime annotation).
As a solution I could think of the following:
- The maven-plugin knows about the source-folders
- from all source-folders which are in target (or other configured name) (or as a positive list: which are in some named directories, defaults src/**) a list of classes (files) is made and used to build an exclusion-list
- This exclusion list gets merged with some eventually existing exclusions
- The exclusions are used when analyzing
I think this would at least lead to a 99% solution