Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom PMD rule with Gradle

Tags:

gradle

pmd

I would like to use the gradle PMD plugin in an enterprise project which is built with gradle.

I have a pmd_rules.xml file which already works, but I can't add own java rules (I get a class not found exception). I followed the tutorial on it's website.

Where do I have to put my own rules so they get recognized by gradle and PMD? Has somebody already done something like that?

pmd.gradle:

apply from: rootProject.file("core/modules.gradle"), to : ext

if(project.name in (modules["modules"] +modules["modules"])){
    apply plugin: 'pmd'

    pmd {
        ignoreFailures = true
        ruleSetFiles = rootProject.files("../repo/pmd_rules.xml")
        sourceSets = [sourceSets.main,sourceSets.test]
        targetJdk = org.gradle.api.plugins.quality.TargetJdk.VERSION_1_7
        ruleSets = []
        toolVersion = "5.0.5"
    }
}
like image 468
Manuel Avatar asked Oct 09 '14 14:10

Manuel


People also ask

What is PMD in gradle?

The PMD plugin performs quality checks on your project's Java source files using PMD and generates reports from these checks.

How do I run a PMD in intelliJ?

The user can run pmd on a single or set of files/folders and see the results in intelliJ. To run the predefined rulesets, go to Tools -> PMD -> PreDefined menu. PMD supports custom ruleset file, to configure goto settings -> PMD and add the rule set files that are required.


1 Answers

tasks.withType(Pmd) {
    pmdClasspath += file("path/to/rules.jar")
}
like image 133
Peter Niederwieser Avatar answered Sep 22 '22 23:09

Peter Niederwieser