Compiler plugins and dependencies

Hi.

I am trying to use a compiler plugin which depends on the scala-xml module.

With Scala < 2.13, the scala-xml module apparently was auto-magically available on the compiler classpath, but this does no longer work with Scala 2.13:

[error] java.lang.NoClassDefFoundError: scala/xml/MetaData
[error] 	at com.sksamuel.scapegoat.io.IOUtils$.writeHTMLReport(IOUtils.scala:24)
[error] 	at com.sksamuel.scapegoat.ScapegoatComponent$$anon$1.run(plugin.scala:174)
[error] 	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1510)
[error] 	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1494)
[error] 	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1486)
[error] 	at scala.tools.nsc.Global$Run.compile(Global.scala:1615)
[error] 	at xsbt.CachedCompiler0.run(CompilerInterface.scala:130)
[error] 	at xsbt.CachedCompiler0.run(CompilerInterface.scala:105)

I tried to add the module to libraryDependencies in build.sbt in various ways (e.g. with compilerPlugin(...)) but no dice. :slightly_frowning_face:

Should compiler plugins simply not depend on other libraries? Are there any known compiler plugins that have workarounds, like shading the module and creating a fatjar?

Thanks!

1 Like

Add to libraryDependencies in plugins.sbt, maybe?

That one is for SBT plugins. Not sure compiler plugins are included.

@sangamon Thanks for you suggestion, I’ll try it. Although I think it will probably not work since as @curoli notes, this changes the classpath for the SBT plugins (or the build of the build) only.

AFAIU, I would need to change the classpath of the JVM, which is called / forked when compiling my project.

I experimented a bit with setting javaOptions but it had no effect.

I managed to create a jar of the compiler plugin including the shaded scala-xml library using the SBT assembly plugin. Seems like the way to go…

PS: adding the scala-xml module to libraryDependencies in project/plugins.sbt did not work.

I raised add some way to specify a dependency for a compiler plugin · Issue #7269 · sbt/sbt · GitHub because I’ve run into a similar problem.