Scala3-migrate: a tool making it easier to migrate to Scala 3

TL DR; Scala3-migrate, a tool to make easier the migration to Scala 3, releases its first version 0.3.1.
We would love to hear your opinion, feedback is welcome!

Scala3-migrate: First release

Scala3-migrate tool is part of a series of initiatives to make the migration to Scala 3 as easy as possible.
The project formerly known as The Scala 2 to Scala 3 typer and implicit resolver has adopted its new name scala3-migrate in early September 2020. We have been working on it actively for the last months, and we are happy to share with you its first release.

The tool is still under development, and we would love to hear from you. Every feedback will help us to build a better tool: typos, clearer log messages, better documentation, bug reports, ideas of features, so please open GitHub issues or comment this contributor post.

Updates

The scope of this tool has been extended to cover more aspects of the migration: migrating dependencies and scalacOptions.

It proposes an incremental approach that can be described as follows:

  • Migrating the library dependencies: using Coursier, it checks, for every library dependency, if there are versions available for Scala 3.
  • Migrating the Scala compiler options (scalacOptions): some compiler options of Scala 2 have been removed in Scala 3, others have been renamed, and some remain the same. This step helps you find how to evolve the compiler options of your project.
  • Migrating the syntax: this step relies on Scalafix and on existing rules to fix deprecated
    syntax that no longer compiles in Scala 3
  • Migrating the code: Scala 3 has a new type inference algorithm that may infer a different type than the one inferred by the Scala 2 compiler. This last step tries to find the minimum set of types to explicitly annotate in order to make the Scala 3 compiler work on a project without changing its meaning.

How to use it

Requirements

  • scala 2.13, preferred 2.13.5
  • sbt 1.4 or higher
  • Disclaimer: This tool cannot migrate libraries containing macros.

Installation

Currently, you can use scala3-migrate via an sbt plugin. You can add it as follows to your build.

// project/plugins.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.4.0")
// sbt-dotty is not required since sbt 1.5.0-M1
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")

4 commands are provided that operate on one module at a time:

  • migrate-libs projectID: helps you update the list of libraryDependencies
  • migrate-scalacOptions projectID: helps you update the list scalacOptions
  • migrate-syntax projectID: fixes a number of syntax incompatibilities in scala 2.13 code
  • migrate projectID: tries compiling your code in scala 3 by adding the minimum required inferred types and implicits.

For detailed documentation regarding scala3-migrate usage, refer to the migration guide in Scala3-migrate section.

20 Likes