Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT Plugin: How to add compiler plugin as a dependency that is not propagated downstream?

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?

like image 209
mirosval Avatar asked May 03 '17 10:05

mirosval


People also ask

Where are sbt plugins stored?

Plugins can be installed for all your projects at once by declaring them in $HOME/. sbt/1.0/plugins/ . $HOME/. sbt/1.0/plugins/ is an sbt project whose classpath is exported to all sbt build definition projects.

What does sbt clean compile do?

Deletes all generated files (in the target directory). Compiles the main sources (in src/main/scala and src/main/java directories). Compiles and runs all tests. Starts the Scala interpreter with a classpath including the compiled sources and all dependencies.

What is a sbt plugin?

The SBT plugin allows you to run Gatling tests from the command line, without the bundle, as well as to package your simulations for Gatling Enterprise.

What is sbt compiler?

sbt is an open-source build tool for Scala and Java projects, similar to Apache's Maven and Ant.


1 Answers

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)
like image 179
flavian Avatar answered Oct 06 '22 01:10

flavian