EDIT flavors and paths:
Currently I have:
sourceSets.whenObjectAdded {
sourceSet ->
def sourceData = rootProject.ext[sourceSet.name]
sourceSet.java.srcDirs = sourceData.javaDirRelease
}
The rootProject.ext is a file where all the productFlavor specific configuration is defined like this:
ext{
flavor1 = [
javaDirRelease : ['src/pathToJavaReleaseFiles']
javaDirDebug : ['src/pathToJavaDebugFiles']
]
}
In the main build.gradle I also do: apply from: 'variants.gradle'
which contains the above ext{} object.
The sourceSets are defined as such:
sourceSets {
flavor1{}
}
This works but I want to do add a sourceSet specific to productFlavor and the buildType like this:
sourceSet.debug.java.srcDirs = 'src/pathToJavaDebugFiles'
Which could be defined for each product flavor and per buildType, but this doesn't work when I try to add it dynamically.
What works for me is this (thanks to this answer How can I specify per flavor buildType sourceSets?):
sourceSets {
flavor1{
def flavorData = rootProject.ext['flavor1']
release {
java.srcDirs = flavorData.javaDirRelease
}
debug {
java.srcDirs = flavorData.javaDirDebug
}
}
}
However I would really like this to be added dynamically, so I can still preserve my configuration file intact. My build configuration is quite complex and not as simple as described here, therefore I don't need a suggestion to put the source files into a folder src/flavor1Debug because this resources are used from other productFlavors also, so this won't work.