4

I have an sbt-plugin that when enabled adds a scalac compiler plugin via scalac options. All is fine with that.

However if the scalac compiler plugin itself has a dependency it needs to use, I cannot get this to work. I've tried:

  • adding the dependency to the target projects libraryDependencies
  • specifying it as a dependency in the sbt-plugin itself.

I think what I need to do is something like (its an auto plugin):

override lazy val projectSettings = Seq(
  ...
  projectsPluginsDependencies ++= Seq(
    "com.typesafe" % "config" % "1.2.1" % Compile.name
  )
  ...
)

If projectsPluginsDependencies was a valid key. Is this possible?

(In fact I'm not even sure how I add the dependency manually to the final project. If a compiler plugin needs dependency X how do you satisfy that? I've tried adding it to project/build.sbt and that doesn't work).

Just to be super clear - I'm not asking how to add a dependency that an sbt-plugin needs. I'm asking how to add a dependency that a compiler plugin needs, that itself is added by an sbt-plugin.

sksamuel
  • 16,154
  • 8
  • 60
  • 108

1 Answers1

0

See Compiler Plugin Support.

autoCompilerPlugins := true

libraryDependencies +=
    compilerPlugin("org.scala-lang.plugins" % "continuations" % scalaVersion.value)

scalacOptions += "-P:continuations:enable"

Try and see if that'll pull in transitive dependencies.

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
  • Is this for the project that uses the compiler plugin? What I'm trying to do is have the user use my SBT plugin, and then the compiler plugin stuff is taken care of automatically. – sksamuel Jul 29 '14 at 17:38
  • This doesn't work. I've updated my sbt plugin to do this: override lazy val projectSettings = Seq( autoCompilerPlugins := true, libraryDependencies ++= Seq( compilerPlugin(GroupId % (ArtifactId + "_" + scalaBinaryVersion.value) % Version % Compile.name) )) But no luck. Caused by: java.lang.ClassNotFoundException: com.typesafe.config.ConfigFactory Which is the same as what I get if you remove the compilerPlugin() and autoCompilerPlugins:=true – sksamuel Jul 29 '14 at 17:44
  • Had this been ever resolved? I encounter the same high level difficulty in a further ambitious scenario at http://stackoverflow.com/questions/34253338/adding-a-library-dependency-via-an-sbt-plugin – matanster Dec 13 '15 at 16:50