Multiple compile tasks against one sourceSet

I’m trying to compile a sourceSet that contains some code that uses ‘sun.misc.Unsafe’ but would like to do so with ‘-Werror’ turned on in javac. This is impossible using a single compiler invocation since you cannot suppress the warnings due to Unsafe usage and they therefore get promoted to errors and cause the compile to fail. I think the simplest way to get what I want is to run an initial compile against the sourceSet including only the ‘bad’ files with -Werror followed by a second compile task that builds all the other classes with -Werror. Whats the most natural way to achieve this in Gradle?

Split the source set as follows:

  1. declare “includes” on the first source-set, including only the “unsafe” classes
  2. declare second source set with the same route and “excludes” the unsafe classes
  3. each sourceset has implicit set of configurations, add the unsafeSourceSet.output and unsafeSourceSet.compile/runtimeClasspath to the approriate configurations

If you have a lot of these, this is a good exercise for a small plugin.

Also, prepare that IDEA will get confused by multiple source-sets under the same root. Try unchecking “module per sourceset” checkbox.