How to suppress PMD warnings during a Maven install

22,582

Solution 1

Just declare failPmdOnViolation property in your pom.xml as true, specify that property in plugin settings instead of hardcoded constant and then you can override it by activating a special profile of from the command line. Or you can refer default expression for failOnViolation plugin property like mvn -Dpmd.failOnViolation=false install

Solution 2

I used below command the same way we use skipTests=true.

mvn clean install -Dpmd.skip=true 

Also for findbugs we can use

-Dfindbugs.skip=true
Share:
22,582
ecbrodie
Author by

ecbrodie

Software Developer at Nulogy, Toronto, ON

Updated on March 23, 2020

Comments

  • ecbrodie
    ecbrodie about 4 years

    I have a Java project that is built using Maven, thus my build process is defined in the pom.xml file of the project. My development team uses a variety of plugins to check the quality of our source code; one such plugin uses PMD to check the code.The plugin makes sure that PMD is run every time we execute mvn install on the project and it will fail the build if there is a violation. Here is the plugin in our pom.xml:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>2.7.1</version>
                <configuration>
                    <targetJdk>1.6</targetJdk>
                    <linkXref>false</linkXref>
                    <failOnViolation>true</failOnViolation>
                    <failurePriority>1</failurePriority>
                    <rulesets>
                        <ruleset>config/pmd-rulesets.xml</ruleset>
                    </rulesets>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    

    My problem is that there are some times -- especially when I am in the middle of developing a task and I want to check out if my code builds, but before I am ready to submit my source code to the SCM for automatic build and release to others -- when I will want to suppress PMD violations from failing my build. I know that one such solution is to go into the code and add annotations to suppress warnings (http://pmd.sourceforge.net/suppressing.html), but I believe that editing source code in this way just to suppress these violations is annoying and error-prone. Another thing I could do is edit my pom and comment out the PMD plugin. However, once again, I find changing a file that is essential to my overall application is annoying and error-prone.

    The solution that my team desires for is one that allows us to simply pass in some sort of flag or argument into our mvn command to quickly tell the build process to skip the PMD plugin. For example, whenever we are running an install at a point in the development phase and we know that the integration tests will probably fail (like, a web service may not be active), we pass the -Dskip.integration.tests=true flag during mvn install. This is a much cleaner solution than having to edit our test files or change pom.xml. I am looking for a similar variable to allows us to quickly skip PMD violations. Thanks!

    PS: I did my homework. The following two Stackoverflow questions did not contain my desired solution: