opticyclic
opticyclic

Reputation: 8106

How Do I Add Multiple Directories And Filter Patterns To A SourceSet?

Due to historical reasons I have resources in multiple directories.

If I needed everything in these directories I could just modify the source set like this:

sourceSets {
    main {
        java {
            srcDir = 'src/main/java'
        }
        resources {
            srcDir = 'src/main/resources'
            srcDir = 'resources'
            srcDir = 'properties'
        }
    }
}

However, I have different include/exclude filters that I need to apply for each directory and they unfortunately conflict each other and any include/exclude filter in the resources it applies it to all 3 of the directories.

How can I filter each directory individually?

Upvotes: 0

Views: 765

Answers (1)

Lukas Körfer
Lukas Körfer

Reputation: 14493

SourceDirectorySet (the class of sourceSets.main.resource) provides a method source(SourceDirectorySet) that allows adding other source sets. New instances of SourceDirectorySet may be created using ObjectFactory.sourceDirectorySet(String, String), so you could try something like the following:

def resourcesSet = objects.sourceDirectorySet("resources", "Resources")
resourcesSet.srcDir 'resources'
// apply filter to resourcesSet

def propertiesSet = objects.sourceDirectorySet("properties", "Properties")
propertiesSet.srcDir 'properties'
// apply filter to propertiesSet

sourceSets {
    main {
        resources {
            source(resourcesSet)
            source(propertiesSet)
        }
    }
}

Upvotes: 1

Related Questions