object scala in compiler mirror not found - running Scala compiler programmatically

前端 未结 4 536
心在旅途
心在旅途 2020-12-19 01:34

Running w/ a simple SBT project w/ Java 7 (details below) and invoking sbt run at the command line (no IntelliJ or anything)

source

impo         


        
4条回答
  •  既然无缘
    2020-12-19 02:08

    This is the one where you have to say:

    trait Probe
    
    object Playground extends App {
      //val compiler = new Global(new Settings())
      val s = new Settings()
      s.embeddedDefaults[Probe]
      val compiler = new Global(s)
      val testFiles = List("Test.scala")
      val runner = new compiler.Run()
      val result = runner.compile(testFiles)
      println(result)
    }
    

    That took me a couple of minutes. That method name, "embeddedDefaults", is as cryptic as any to come out of sbt.

    The comment on MutableSettings (which suggests a side effect):

      /** Initializes these settings for embedded use by type `T`.
      * The class loader defining `T` should provide resources `app.class.path`
      * and `boot.class.path`.  These resources should contain the application
      * and boot classpaths in the same form as would be passed on the command line.*/
    

    The indentation is as in the source code.

提交回复
热议问题