14
votes

I have a library that uses the macro paradise plugin (referred to as macro-provider library). In the build.sbt,

addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.0" cross CrossVersion.full)

to gain access to the macro annotations.

When adding the macro library as a libraryDependency to a separate project (referred to as macro-consumer project), the annotations are present, but the macro implementation is never called. Adding the macro paradise compiler plugin to the macro-consumer project libraryDependencies solves the problem.

Is it possible to include compiler plugins as transitive dependencies? This would free consumers of the macro library from adding the required plugin.


Update #1:

The addCompilerPlugin helper adds the dependency to the libraryDependencies and sets the dependency with a configuration = Some("plugin->default(compile)") within the macro-provider library.

Adding the paradise dependency in the libraryDependencies of the macro-provider library causes the artifact to show up in the macro-consumer project. It does not add the dependency as a compiler plugin.

Update #2:

Setting autoCompilerPlugins := true in the macro-consumer project in conjunction with Update #1 does not resolve the issue.

1

1 Answers

1
votes

The only way I found to resolve this issue was by adding a sbt-plugin sub-module that includes the settings required. The plugin is very basic,

package fixme

import sbt._
import Keys._

object Plugin extends sbt.Plugin {
  val paradiseVersion = "2.0.0"
  val fixmeVersion = "1.4"
  val fixmeSettings: Seq[Setting[_]] = Seq(
    resolvers += "tysonjh releases" at "http://tysonjh.github.io/releases/",
    libraryDependencies <++= (scalaVersion) { v: String ⇒
      (if (v.startsWith("2.10")) List("org.scalamacros" %% "quasiquotes" % paradiseVersion % "compile")
      else Nil) :+
        "org.scala-lang" % "scala-reflect" % v % "compile" :+
        "com.tysonjh" %% "fixme" % fixmeVersion % "compile"
    },
    addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full))
}

This can be used by including in your project/plugins.sbt,

resolvers += "tysonjh releases" at "http://tysonjh.github.io/releases/"

addSbtPlugin("com.tysonjh" % "sbt-fixme" % "1.4")

and the build.sbt file,

fixmeSettings

The sbt-plugin settings add the macro paradise plugin as a compiler dependency and the macro implementation as a library dependency.