Search code examples
pmd

PMD violationSuppressXPath for all REST @GET methods?


I am trying to narrow down the PMD rules, how can I exclude all REST methods which are annotated with @GET from PMD checks?


Solution

  • We are using for example this rules to suppress checks on REST methods for final declaration. Maybe you need similar?

    <rule ref="rulesets/java/optimizations.xml/MethodArgumentCouldBeFinal">
        <properties>
            <!-- Ignore Rest resources -->
            <property name="violationSuppressXPath" value="
                //ClassOrInterfaceBodyDeclaration/Annotation/MarkerAnnotation//Name[@Image='GET'] | 
                //ClassOrInterfaceBodyDeclaration/Annotation/MarkerAnnotation//Name[@Image='POST']|
                //ClassOrInterfaceBodyDeclaration/Annotation/MarkerAnnotation//Name[@Image='PUT'] | 
                //ClassOrInterfaceBodyDeclaration/Annotation/MarkerAnnotation//Name[@Image='DELETE']" />
        </properties>
    </rule>