From 7af0fea54ef677b5b57c082ebfbfce08fe56fa71 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Fri, 30 Oct 2015 19:18:12 +0100 Subject: [PATCH] Don't pass `-J` option to local Java compiler These options can only be given to a forked Java compiler. If we run a local java compiler, we filter these options out and emit a warning. Fixes sbt/sbt#1968 --- .../src/main/scala/sbt/compiler/javac/LocalJava.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compile/src/main/scala/sbt/compiler/javac/LocalJava.scala b/compile/src/main/scala/sbt/compiler/javac/LocalJava.scala index 81f4e1293..42ef0ed6e 100644 --- a/compile/src/main/scala/sbt/compiler/javac/LocalJava.scala +++ b/compile/src/main/scala/sbt/compiler/javac/LocalJava.scala @@ -66,6 +66,14 @@ final class LocalJavaCompiler(compiler: javax.tools.JavaCompiler) extends JavaCo val diagnostics = new DiagnosticsReporter(reporter) val fileManager = compiler.getStandardFileManager(diagnostics, null, null) val jfiles = fileManager.getJavaFileObjectsFromFiles(sources.asJava) - compiler.getTask(logWriter, fileManager, diagnostics, options.asJava, null, jfiles).call() + + // Local Java compiler doesn't accept `-J` options. We emit a warning if we find + // such options and don't pass them to the compiler. + val (invalidOptions, cleanedOptions) = options partition (_ startsWith "-J") + if (invalidOptions.nonEmpty) { + log.warn("Javac is running in 'local' mode. These flags have been removed:") + log.warn(invalidOptions.mkString("\t", ", ", "")) + } + compiler.getTask(logWriter, fileManager, diagnostics, cleanedOptions.asJava, null, jfiles).call() } } \ No newline at end of file