addCompilerPlugin
is just a shortcut for modifying a particular setting key, while enablePlugins
is a method to modify the project configuration itself. Therefore, these things are on different levels, and so are handled differently for your purpose.
To ensure that enabling your plugin would also enable other plugins, you need to modify the requires
declaration in your plugin:
object YourPlugin extends AutoPlugin {
override def requires: Plugins = FirstDependencyPlugin & SecondDependencyPlugin
}
Now, when your plugin is added to a project:
lazy val someProject = project.enablePlugins(YourPlugin)
then the FirstDependencyPlugin
and SecondDependencyPlugin
plugins will also be enabled.
To enable a compiler plugin, you just need to ensure that your plugin provides the setting definition returned by addCompilerPlugin
:
object YourPlugin extends AutoPlugin {
override def projectSettings: Seq[Def.Setting[_]] = super.projectSettings ++ Vector(
addCompilerPlugin("com.example" % "some-plugin" % "1.2.3")
)
}
Now, when your plugin is added to a project, the Def.Setting[_]
provided by it will be automatically applied to this project, and it will use the specified compiler plugin to build your code.