SBT Plugin: How to add a compiler plugin as a dependency that does not propagate with the flow?

I am writing an SBT plugin. I would like to use the Circe JSON library, but this requires the Macro Paradise compiler plugin on Scala 2.10.

Usually you add compiler plugins to plugins build.sbtand SBT before project/plugins.sbt.

Now, when you create the SBT plugin, other plugins become dependent, so you put them in build.sbt, and they apply to projects where you use your SBT plugin.

When I put the following snippet in build.sbtmy SBT plugin:

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

Does the Paradise compiler plugin apply to subsequent projects?

+4
source share
1 answer

Compiler plugins are not distributed by default, but in fact they will be required by subordinates as a dependency, and you will not be able to circumvent this requirement.

The reason is simple, their code will be compiled in another compilation unit, so as long as you have functions that depend on the compiler plug-in that are found in the end code base, you will also need to write a note on this plug-in to explicitly add the dependency.

Hope this helps, and take, for example, the really popular Monocle lib here . Annotations will not expand without paradise, for example, so this is all a question of what the end user needs.

Quote

, @Lenses, :

addCompilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full)
+5

Source: https://habr.com/ru/post/1676243/


All Articles