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?
chrisdennis (Chris Dennis) #1
ddimitrov (Dimitar Dimitrov) #2
Split the source set as follows:
- declare “includes” on the first source-set, including only the “unsafe” classes
- declare second source set with the same route and “excludes” the unsafe classes
- each sourceset has implicit set of configurations, add the
unsafeSourceSet.compile/runtimeClasspathto 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.