Reputation: 15
I am trying to develop a very small autoplugin to override the local configuration of all projects and subprojects. Specifically, I'd like my plugin to change the scalaVersion and add one option to the scalacOptions of the project that includes it. I have read in the documentation that one can alter the order in which settings are assigned, but it seems that I am not assigning them to the correct project. This is the code I have so far:
// build.sbt
import AddSettings._
lazy val root = (project in file("."))
.settingSets(userSettings, defaultSbtFiles, autoPlugins, buildScalaFiles)
.settings(
sbtPlugin := true,
name := "sbt-scalafix-config",
organization := "io.prl-prg",
version := "0.0.1",
addSbtPlugin("org.some" % "some-other-plugin" % "0.5.3")
)
// PluginCode.scala
package config
import sbt._
import sbt.Keys._
object PluginCode extends AutoPlugin {
override def trigger = allRequirements
override lazy val projectSettings = Seq(
scalaVersion := "2.12.3",
scalacOptions := Seq( "-Yrangepos" )
)
println("[PluginCode Setup] Hello World!")
}
Any help is appreciated.
Upvotes: 0
Views: 1165
Reputation: 22085
You really don't want to use addSettings
, as
AutoPlugin
s in your build, and,AutoPlugin
s are not supposed to overwrite settings in projects. Projects should always have the final say about their own settings, so that makes sense.
You can easily do the scalacOptions
part by using +=
instead of :=
(in the plugin and in the projects). In general, you should virtually never use :=
with Seq-settings, and scalacOptions
in particular.
override def projectSettings = Seq(
scalacOptions += "-Yrangepos"
)
For scalaVersion
, well, if the project explicitly sets scalaVersion
, there's nothing your AutoPlugin
can do to overrule it. And it shouldn't be able to. However, you could get the effect you want if the project does not define scalaVersion
at the project-level (but maybe at the in ThisBuild
level, for example).
Upvotes: 1