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:

sbt.version=0.13.16

Next we need to update our build.sbt file with some new settings.

Change your scala version to 2.12.3:

scalaVersion := "2.12.3"

Set the global version of SBT to 1.0.3:

sbtVersion in Global := "1.0.3"

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:

crossSbtVersions := Vector("0.13.16", "1.0.3")

The full list of changes to build.sbt are:

scalaVersion := "2.12.3"

sbtVersion in Global := "1.0.3"

scalaCompilerBridgeSource := {
  val sv = appConfiguration.value.provider.id.version
  ("org.scala-sbt" % "compiler-interface" % sv % "component").sources
}

crossSbtVersions := Vector("0.13.16", "1.0.3")

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:

  1. 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.

  2. 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.

  3. sbt.BuildStructure does not exist in SBT 1.x. This has been moved to sbt.internal.BuildStructure.

  4. There were a lot of deprecated warnings. Please see Migrating from SBT 0.13.x on how to fix them all.

  5. 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:

  1. Extend AutoPlugin instead of Plugin
  2. Add an autoImport module under AutoPlugin for any settings you want automatically imported into SBT.
  3. Add the following settings:
 override def requires = plugins.JvmPlugin
 override def trigger = allRequirements

Please see sbt-ctags SBT 1x Compatibility PR for an example.

  1. 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.