I have an sbt plugin, that needs to get compiler AST’s from source files. I tried to create a new compiler with the following code:
val settings = new Settings
settings.usejavacp.value = true
val compiler = new tools.nsc.interactive.Global(settings, new StoreReporter())
But I get the following error:
java.lang.Error: typeConstructor inapplicable for <none>
It seems that it somehow clashes with sbt’s internal compiler.
So, is there a way to get AST’s for those files from inside sbt?
Or maybe it is possible to get them from sbt’s compiler directly? (that would be even better, since I would not need to recompile everything every time)
EDIT:
Seems that using tools.nsc.Global instead of “interactive” one does not throw an error, but I don’t know how to get ASTs from it.
EDIT:
Well, tools.nsc.Global fails with the same error when I try to compile some files 🙁
SBT FAQ states that I should use some “representative type” when initializing my compiler – settings.embeddedDefaults[MyType]. But I can’t figure out exactly what I should send to it. Can somebody help me with it?
This line means to use the value of the
java.class.pathsystem property as the classpath for the compiler:In sbt, this is only going to include the launcher jar because that is all that is on the classpath when the jvm is initialized.
The launcher jar has been processed with ProGuard, so it contains incomplete Scala classes and should never be on a compiler classpath.
Instead, explicitly set the classpath according to your needs: