Scala Steward can run Scalafix rewrite rules for version updates to not only bump version numbers but to also adapt the code for the new version. This allows to automatically rewrite deprecated code or code that would not compile with the new version of the dependency.
Here are two pull requests that demonstrate this feature:
- https://github.com/barambani/http4s-extend/pull/67/files
- https://github.com/fthomas/scalafix-test/pull/6/files
And here are all pull requests where Scala Steward applied Scalafix migrations:
Scala Steward contains a list of migration rules combined with metadata that describes to which updates they are applicable. When it prepares a pull request and finds that one or more rules match the current update, Scala Steward applies these migration rules via the sbt-scalafix plugin which resolves those rules and edits the source code accordingly.
See the Scalafix Developer Guide for more information about writing rewrite rules or have a look at the existing migration rules for inspiration. Rules in Scala Steward must be accessible via the github:, the http: or the dependency: schemes.
After you have written a new migration rule for a new version of your project, Scala Steward needs to be made aware of it. Creating a pull request that adds the new rule to the list of migrations is enough for that. Once that pull request is merged, Scala Steward will start using this migration.
When running Scala Steward you can also specify files or URLs (via the
--scalafix-migrations
command-line option) that contain additional
migrations which are not present in the default list.
These files are in HOCON format and should look like this:
migrations = [
{
groupId: "org.http4s",
artifactIds: ["http4s-.*"],
newVersion: "0.20.0",
rewriteRules: ["github:http4s/http4s/v0_20?sha=v0.20.11"],
doc: "https://github.com/http4s/http4s/blob/v0.20.0/docs/src/main/tut/upgrading.md"
}
]
Pull requests that added migration rules can be found here.