Gradle build using sourceSets

I’m trying to use the sourceSets of my gradle project and i couldn’t find a working solution for my scenario:
I have 2 different build types: full and basic, the full need to use\compile all java files while the basic needs to exclude several fails.
In order to implement the 2 builds i am using sourceSets of ‘main’ and ‘simple’, the ‘main’ is used for the full while the ‘simple’ for the basic. in the ‘simple’ sourceSet i added java.exclude for the files i want to remove from the compilation but from what i understand the sourceSet automatically change the source folder to be something like src\SOURCE-SET_NAME\java… instead of src\java… and that’s the reason that the exclude action doesn’t succeed.

My question is, how can i use different build settings or sourceSets but keep using the same source folder?

Hi, are you using a custom project layout or you apply the default maven one?
Anyways you can try this, which help you to define a custom sourceSets:

      //just put the name of the packages that you want
      java.srcDirs=files(list of simple packages name)
     // In case you have a custom project layout, otherwise you can give up the else section
     java.srcDirs=files(list of main packages name)

I suggest that you define a variable which you passed as an argument during the build, this will serve you as selector for the build type (simple or main). And using the files() method you can include the list of packages that you want to compile.


Thanks for the answer but our files are located at the same path and i would like to keep that as is for the moment.
From my tests, the exclude in the ‘simple’ sourceSet doesn’t work on files in the ‘main’

Did you try to exclude files like that?

Hi again,
May be you can try the classical way, that should work:

              srcDir 'src'
              exclude '**/unWantedList**'


finally i found out that the only way to do it correct on Gradle is to split my code into different folders and compile them according to the output i need (main, simple) and it works like i needed