Create many sourceSets in Gradle

I have a project in which there are folder with different zip archives. I want to extract them and for each to make some checks. But want reports to be separated. For example pmd check. So to be separated files from each zip file has to be but in different sourseSets and when call

gradle check

For each of the dirs to generate reports with the checks.

Input files: sources1.zip,sources2.zip,sources3.zip,sources4.zip Each of the zip contains separate project. for example:

src/main/java/sources1/Example.java
src/main/java/sources2/App.java

.... When run checks to be generated

build/reports/pmd/sources1SourceSet.html
build/reports/pmd/sources2SourceSet.html
build/reports/pmd/sources3SourceSet.html
build/reports/pmd/sources4SourceSet.html

So I want to declare this different sourceSets according the name of the zips and not to do it manually, but don't know how.

sourceSets {
    sourcest1{
        java {
            srcDirs  file("...")
        }
    }
}

Is there are another easy way to separated checks without creating new sourceSets for each zip?

Answers


one way to start you could create dedicated tasks for each zip. This can be done in a loop:

["source1", "source2", "source3"].each{ sourceName ->
    tasks.create("pmd${sourceName}", Pmd){
        reports.html.reportsDir = "$buildDir/reports/pmd${sourceName}"

        source = zipTree("file/to/$sourceName.zip")
        ...
    }
}

cheers


Need Your Help

Load Fragment before Navigation Drawer closes

android android-fragments navigation

I have implemented a navigation drawer and I want to load my fragment before the navigation drawer closes. Currently, the fragment loads in parallel with the drawer closing, so if the fragment is h...

Making hibernate ignore normal get methods

hibernate methods mapping field

I have an application that was mapped using fields, so after reading about it I have decied to move to methods. However now I have a problem where in one of my abstract class that has method getFul...