@@ -604,54 +604,73 @@ object Compiler {
604604 }
605605 }
606606
607- private def getCompilationOptions (
608- inputs : CompileInputs ,
609- logger : Logger ,
610- newClassesDir : Path
611- ): CompileOptions = {
612- // Sources are all files
613- val sources = inputs.sources.map(path => converter.toVirtualFile(path.underlying))
614- val classpath = inputs.classpath.map(path => converter.toVirtualFile(path.underlying))
615- def existsReleaseSetting = inputs.scalacOptions.exists(opt =>
607+ /**
608+ * Bloop runs Scala compilation in the same process as the main server,
609+ * so the compilation process will use the same JDK that Bloop is using.
610+ * That's why we must ensure that produce class files will be compliant with expected JDK version
611+ * and compilation errors will show up when using wrong JDK API.
612+ */
613+ private def adjustScalacReleaseOptions (
614+ scalacOptions : Array [String ],
615+ javacBin : Option [AbsolutePath ],
616+ logger : Logger
617+ ): Array [String ] = {
618+ def existsReleaseSetting = scalacOptions.exists(opt =>
616619 opt.startsWith(" -release" ) ||
617620 opt.startsWith(" --release" ) ||
618621 opt.startsWith(" -java-output-version" )
619622 )
620- def sameHome = inputs. javacBin match {
623+ def sameHome = javacBin match {
621624 case Some (bin) => bin.getParent.getParent == JavaRuntime .home
622625 case None => false
623626 }
624627
625- val scalacOptions = inputs. javacBin.flatMap(binary =>
628+ javacBin.flatMap(binary =>
626629 // <JAVA_HOME>/bin/java
627630 JavaRuntime .getJavaVersionFromJavaHome(binary.getParent.getParent)
628631 ) match {
629- case None => inputs. scalacOptions
630- case Some (_) if existsReleaseSetting || sameHome => inputs. scalacOptions
632+ case None => scalacOptions
633+ case Some (_) if existsReleaseSetting || sameHome => scalacOptions
631634 case Some (version) =>
632635 try {
633636 val numVer = if (version.startsWith(" 1.8" )) 8 else version.takeWhile(_.isDigit).toInt
634637 val bloopNumVer = JavaRuntime .version.takeWhile(_.isDigit).toInt
635638 if (bloopNumVer > numVer) {
636- inputs. scalacOptions ++ List (" -release" , numVer.toString())
639+ scalacOptions ++ List (" -release" , numVer.toString())
637640 } else {
638641 logger.warn(
639642 s " Bloop is runing with ${JavaRuntime .version} but your code requires $version to compile, " +
640643 " this might cause some compilation issues when using JDK API unsupported by the Bloop's current JVM version"
641644 )
642- inputs. scalacOptions
645+ scalacOptions
643646 }
644647 } catch {
645648 case NonFatal (_) =>
646- inputs. scalacOptions
649+ scalacOptions
647650 }
648651 }
652+ }
653+
654+ private def getCompilationOptions (
655+ inputs : CompileInputs ,
656+ logger : Logger ,
657+ newClassesDir : Path
658+ ): CompileOptions = {
659+ // Sources are all files
660+ val sources = inputs.sources.map(path => converter.toVirtualFile(path.underlying))
661+ val classpath = inputs.classpath.map(path => converter.toVirtualFile(path.underlying))
662+
663+ val scalacOptions = adjustScalacReleaseOptions(
664+ scalacOptions = inputs.scalacOptions,
665+ javacBin = inputs.javacBin,
666+ logger = logger
667+ )
649668
650669 val optionsWithoutFatalWarnings = scalacOptions.filter(_ != " -Xfatal-warnings" )
651- val isFatalWarningsEnabled = scalacOptions.length != optionsWithoutFatalWarnings.length
670+ val areFatalWarningsEnabled = scalacOptions.length != optionsWithoutFatalWarnings.length
652671
653672 // Enable fatal warnings in the reporter if they are enabled in the build
654- if (isFatalWarningsEnabled )
673+ if (areFatalWarningsEnabled )
655674 inputs.reporter.enableFatalWarnings()
656675
657676 CompileOptions
0 commit comments