I have a project including both Java and Scala sources. The Java sources include one file which uses the sun.misc.Unsafe
API. We are well aware of the risks of using this API and want to suppress the warnings in this file. However, we also want to treat warnings as errors on the rest of the Java and Scala code.
My build.sbt
includes these lines:
lazy val root = (project in file(".")).
settings(
// ...
Compile / javacOptions ++= Seq(
"-Xlint:all",
"-Werror",
"-XDenableSunApiLintControl"
),
Compile / fork := true,
Compile / javaOptions += "-XDenableSunApiLintControl",
// ...
)
I understand from an SO comment on a related post that I must fork a new JVM for -XDenableSunApiLintControl
to take effect. For this reason, I specified Compile / fork := true
and respecified the option in the Compile / javaOptions
.
Unfortunately, I still see the warning reported as an error.
My Java file starts this way:
package is.hail.annotations;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
@SuppressWarnings("sunapi")
public final class Memory {
Which successfully suppresses the warnings when using Gradle with
compileJava {
options.compilerArgs << "-Xlint:all" << "-Werror" << "-XDenableSunApiLintControl"
}
tasks.withType(JavaCompile) {
options.fork = true // necessary to make -XDenableSunApiLintControl work
}
How do I enable suppression of the sun.misc.Unsafe
API in SBT?