Skip to content

Instantly share code, notes, and snippets.

@pshirshov
Created July 3, 2018 21:30
Show Gist options
  • Save pshirshov/8ea3691dc5e6681f6a4b8a306201ee63 to your computer and use it in GitHub Desktop.
Save pshirshov/8ea3691dc5e6681f6a4b8a306201ee63 to your computer and use it in GitHub Desktop.
scala.tools.nsc invokation example
private def isRunningUnderSbt: Boolean = {
Option(System.getProperty("java.class.path")).exists(_.contains("sbt-launch.jar"))
}
import scala.tools.nsc.{Global, Settings}
val settings = new Settings()
settings.d.value = ctarget.toString
settings.feature.value = true
settings.warnUnused.add("_")
settings.deprecation.value = true
settings.embeddedDefaults(this.getClass.getClassLoader)
if (!isRunningUnderSbt) {
settings.usejavacp.value = true
}
val g = new Global(settings)
val run = new g.Run
run.compile(out.allFiles.map(_.toFile.getCanonicalPath).toList)
assert(run.runIsAt(run.jvmPhase.next))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment