Migrating SBT Plugins from 0.13.x to 1.x
Migrating SBT 0.13.x plugins to SBT 1.x can be a little confusing. Here I try to document the steps I followed to migrate two plugins from 0.13.x to 1.x.
Cross-Building
The first thing you need to do is bump your SBT version to 0.13.16 or later, as this lets you cross-compile your plugin between 0.13.x and 1.x. Update your project/build.properties file with the following:
.version=0.13.16 sbt
Next we need to update our build.sbt file with some new settings.
Change your scala version to 2.12.3:
:= "2.12.3" scalaVersion
Set the global version of SBT to 1.0.3:
:= "1.0.3" sbtVersion in Global
Add a scalaCompilerBridgeSource setting:
:= {
scalaCompilerBridgeSource val sv = appConfiguration.value.provider.id.version
("org.scala-sbt" % "compiler-interface" % sv % "component").sources
}
Add cross-building versions you require:
:= Vector("0.13.16", "1.0.3") crossSbtVersions
The full list of changes to build.sbt are:
:= "2.12.3"
scalaVersion
:= "1.0.3"
sbtVersion in Global
:= {
scalaCompilerBridgeSource val sv = appConfiguration.value.provider.id.version
("org.scala-sbt" % "compiler-interface" % sv % "component").sources
}
:= Vector("0.13.16", "1.0.3") crossSbtVersions
Feel free to change the Scala version to the latest 2.12.x version and SBT to the latest 1.x version when applying these settings.
Run a clean test across all versions through SBT:
^ ;clean;test
The ^ will run all SBT tasks across all versions defined in crossSbtVersions. This new syntax is documented here
Fixing issues
Here are some of the issues I ran across and their solutions:
For any SBT plugins that your plugin depends on, you need to get the latest version of the plugin that supports 1.x. If the plugin doesn’t support 1.x, you either can’t update your plugin to 1.x or find another plugin or a workaround to get the same functionality without including that plugin.
sbt.Process does not exist in SBT 1.x. This has been removed and you can simply use the Scala’s sys.process.Process instead.
sbt.BuildStructure does not exist in SBT 1.x. This has been moved to sbt.internal.BuildStructure.
There were a lot of deprecated warnings. Please see Migrating from SBT 0.13.x on how to fix them all.
Your plugin is not an AutoPlugin and extends sbt.Plugin instead. SBT 0.13.15 onwards recommends the creation of an AutoPlugin instead of Plugin.
If you have a simple plugin you can do the following:
- Extend AutoPlugin instead of Plugin
- Add an autoImport module under AutoPlugin for any settings you want automatically imported into SBT.
- Add the following settings:
override def requires = plugins.JvmPlugin
override def trigger = allRequirements
Please see sbt-ctags SBT 1x Compatibility PR for an example.
- Scripted failures. The scripted plugin might get different paths to dependencies than it did previously. Simply fix this with the new paths required.
Publish
^ publish
Should publish both the sbt/0.13 and sbt/1.0 versions of your plugin. If you use a service like Bintray you’ll find both versions uploaded when you publish to Bintray.