Help with PMD SourceSet


(Tim Razik) #1

Is there a way to tell pmd to exclude specific srcDirs from a sourceSet?

I have a project that uses Axis to generate wsdl and xsd java source.
To allow for the incremental build, we put the generated files into two folders

$buildDir/generated-xsd
$buildDir/generated-wsdl

We then add those two directories to the java source sets.
I would like for PMD to run only on the non generated source. I have added this pmd block to build.gradle but it is impacting the java compile as well.

sourceSets {
                         main {
                                 java {
                                         srcDirs "$project.buildDir/generated-xsd", "$project.buildDir/generated-wsdl"
                                 }
                         }
 }

 pmd {
        sourceSets {
            main {
                 java {
                      //Exclude generated sources
                      srcDirs = srcDirs - (files("${buildDir}/generated-xsd") + files("${buildDir}/generated-wsdl"))
                       }
           }
         }
 }//end pmd
 task timTest {

         doLast {
                 project.pmd.sourceSets.main.java.srcDirs.each {println it}
                 project.sourceSets.main.java.srcDirs.each {println it}
         }
 }

I can’t use the PMD excludes as that uses name spaces and there isn’t a specific naming standard in that generated code that I can easily use to sepearate it out from the original java source.

When I execute my timTest task I was surprised to see that the pmd source set modified the project sourceSet. I would have expected PMD to have it’s own sourceSet.


(Tim Razik) #2

An update here. I have stared to try to use the exclude and directly update the source.
If I am reading the doc and the gradle java code correctly setSource should clear the source list
I am playing with something like the task type below. Two notes

  1. When I print out the source, it only has the source I want, but regardless running the task pmdMain seems to ignore that and use sourceSets.main.

  2. As I mentioned in the original post, I tried playing with the include/exclude but that does not allow me to exclude path like “${buildDir}/generated-xsd/**”.

    tasks.withType(Pmd) {
    // This does not work because it assumes relative path
    //include “/src/main/java//*.java”
    //exclude “${buildDir}/generated-xsd/**”

     setSource(fileTree(dir: "${projectDir}/src/main/java/", include: "**/*.java"))
     //prints out the correct files but seems to be ingored
     source.each{println "${name} Include Src: " + it}
    

    }