Play framework with Scala 3

Viewed 2894

I'm trying to update a Play Framework (2.8.8) project from Scala 2.13 to Scala 3 using auto-migration plugin.

Problem arises for dependencies that are not explicitly listed in build.sbt but rather (as far as I understand) resolved from "com.typesafe.play" % "sbt-plugin" % "2.8.8"

[info] com.typesafe.play:twirl-api:1.5.1 -> "com.typesafe.play" % "twirl-api_2.13" % "1.5.1"
[info] com.typesafe.play:play-docs:2.8.8:docs -> "com.typesafe.play" % "play-docs_2.13" % "2.8.8" % "docs"
[info] com.typesafe.play:play-logback:2.8.8  -> "com.typesafe.play" % "play-logback_2.13" % "2.8.8"
[info] com.typesafe.play:play-test:2.8.8:test -> "com.typesafe.play" % "play-test_2.13" % "2.8.8" % "test"
[info] com.typesafe.play:filters-helpers:2.8.8 -> "com.typesafe.play" % "filters-helpers_2.13" % "2.8.8"
[info] com.typesafe.play:play-server:2.8.8 -> "com.typesafe.play" % "play-server_2.13" % "2.8.8"
[info] com.typesafe.play:play-akka-http-server:2.8.8 -> "com.typesafe.play" % "play-akka-http-server_2.13" % "2.8.8"

It looks like sbt-plugin is only published for SBT 1.x and Scala 2.12 (ie here) but all listed incompatibilities (see above) already have 2.13 version which would be fine with Scala 3 CrossVersion.for3Use2_13 flag.

Is there any way around it (overriding dependencies?) or am I stuck until sbt-plugin for 2.13 is released?

3 Answers

I think you're confusing two separate issues: the Scala version used to build your sbt build, and the Scala version used to build your program. For the former you have to use Scala 2.12. For the latter, you can use whatever you want, including 3.0.0. The two don't have to match.

Play Framework does not support Scala 3, as of August 2021. Play depends on lots of other libraries, not all of them support Scala 3 yet.

So even if you configure sbt correctly, as per Matthias' answer, apparently you still cannot use Scala 3 yet.

Here's a discussion thread over at the Play Framework forum, about Scala 3:

https://discuss.lightbend.com/t/scala-3-0-support/7729/10

[...] It’s not as easy as simply making Play itself work with Scala 3. Play depends on various other projects and libraries

I have something like this included in my build.sbt so that I can build my project with 3.0 and still depend on libraries only available using 2.13

val scala3Version = "3.0.2"

val libVersion = "0.0.1"

lazy val projectName = project
    .in(file("exampleproject"))
    .settings(
        ...,
        libraryDependencies ++= Seq(
            ...,
            "com.example.lib" %% "lib-name" % libVersion,
        ).map(_.cross(CrossVersion.for3Use2_13))
    )

Their documentation has changed a lot, but is relatively stable now: Scala 3 Migration Guide Doc

Related