Disable PMD Plugin to Run for Test Sources

Posted by & filed under , .

PMD LogoI use PMD in my Gradle builds quite a bit. (Maybe a bit more nowadays that the FindBugs peeps seem to be struggling with that project — see this email from Andrey on this: https://mailman.cs.umd.edu/pipermail/findbugs-discuss/2016-November/004321.html).

The issue I had with it is that there is no way to quickly turn off their checks for the src/test/... source sets — in other words not analyze my unit test sources. And since I have configured the plugin to fail the build when it finds issues, I occasionally find myself failing my builds because my unit test code is not that clean and kosher — which is not something that bothers me to be honest. (Of course I prefer unit test code that I can read and understand but I would not enforce any code styles or checks on my team.)

This comes down to the fact that the PMD plugin introduces 2 tasks: pmdMain (for src/main sources) and pmdTest (for src/test sources). And I have tried to look at the gradle task graphs and alter it until it occurred to me that the solution is more simple than that:

Gradle allows any task to be enabled and disabled via the enabled property — so to turn pmdTest all one needs in your build.gradle file is:

pmdTest.enabled = false

This of course works for any other task you want to turn off — checkStyleTest, findBugsTest and so on included 😉

Leave a Reply

Your email address will not be published.