9

I've have a Groovy project built with Gradle (1.8) in which some Java classes report the following compiler warning message:

warning: Unsafe is internal proprietary API and may be removed in a future release
import sun.misc.Unsafe;

Is there a way to suppress that error message? I've found some answers suggesting to use the javac compiler option -XDignore.symbol.file but I'm unable to apply it in the Gradle build when using the Groovy plugin.

Any solution ?

Thanks

pditommaso
  • 3,186
  • 6
  • 28
  • 43

1 Answers1

7

Add following to your gradle.build file

compileJava {
    options.compilerArgs << '-XDignore.symbol.file'
    options.fork = true // may not needed on 1.8
    options.forkOptions.executable = 'javac' // may not needed on 1.8
}

fork is required on gradle 1.6, not sure about 1.8 update: it's still required on 1.8

Viktor Aseev
  • 698
  • 4
  • 9
  • 2
    All of this is still needed in 1.8/1.9. What it does is to force Gradle into using the command-line compiler. This is necessary because the Java compiler API doesn't support the `-XDignore.symbol.file` option. Note that using the command-line compiler may slow down builds (in particular multi-project builds). – Peter Niederwieser Oct 24 '13 at 03:08
  • It is not working. I'm still getting the warning message(s). Since they are produced by the ':compileGroovy' step, should not the compilerArgs applied to the groovy compiler options? – pditommaso Oct 24 '13 at 08:38
  • Actually it worked, but I had to move the Java sources into the src/main/java directory (instead of src/main/groovy). As a side effect, now the Groovy compilation fails because it do not "see" the java compiled classes. – pditommaso Oct 24 '13 at 09:14
  • You didnt mention that you compile java files with groovy. Why your java files stored in groovy source folder? Gradle builds assume lot of defaults and if you do something strange, you need to say gradle about this. – Viktor Aseev Oct 24 '13 at 10:11
  • Moving the Java sources to a separate folder (let's says `src/main/java` instead of `src/main/groovy`) then the compiler option you suggested works, BUT the groovy compilation fails because it is unable to find the Java classes compiled by the `compileJava` stage. – pditommaso Oct 24 '13 at 15:18
  • 1
    You didn't mention that you were using joint compilation. Try to move the sources back and replace `compileJava` with `compileGroovy` above. I'm not completely sure if these options work for joint compilation, but it's worth a try. – Peter Niederwieser Oct 25 '13 at 06:08