How to compile different sources than main source set?

I’m late to the ant -> gradle migration on Android but trying to improve that.
My build process involves preprocessing my whole java source tree and outputting everything to another folder: build/preprocessed/java

I managed to do the actual preprocessing with gradle, and include it as a separate task to the actual build, and get it to build, but only by using the preprocessed sources as the main source set:

sourceSets { = [‘build/preprocessed/java’]

The problem with this is that Android Studio now uses this folder for the default sources that I edit, which is of course not what I want. I want to keep editing the files found in src/main/java, but compile the preprocessed ones.

Anything that I can find on the subject (which is not a lot), says to change the main source set as described but doesn’t address this IDE editor problem.

Any insight on how to do this would be greatly appreciated