问题
I'm writing a SBT plugin. I would like to use Circe JSON library, but it requires the Macro Paradise compiler plugin on Scala 2.10.
Normally you add compiler plugins to build.sbt
and SBT plugins to project/plugins.sbt
.
Now when you're building a SBT plugin, the other plugins become dependencies, so you put them to build.sbt
and they are propagated to the projects where you use your SBT plugin.
When I put the following snippet in build.sbt
of my SBT plugin:
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
Does the Paradise compiler plugin propagate to downstream projects?
回答1:
Compiler plugins are not propagated by default, but they will in fact be required by downstream users as a dependency, and there is no way for you to bypass this requirement.
The reason is simple, their code will be compiled in a different compilation unit, so as long as you have features that depend on the compiler plugin that will be found in the end codebase, you'll also need to stick a note on this plugin to explicitly add the dependency.
Hope this helps, and take for example the really popular Monocle lib here. Annotations won't expand without paradise for instance, so it's all a question of what the end user will need.
Quote
If you want to use macro annotations such as @Lenses, you will also need to include:
addCompilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full)
来源:https://stackoverflow.com/questions/43757369/sbt-plugin-how-to-add-compiler-plugin-as-a-dependency-that-is-not-propagated-do