playframework / twirl

Twirl is Play's default template engine
Apache License 2.0
549 stars 108 forks source link

Added support for switching the default "import" between Scala 2 and Scala 3 #613

Closed tototoshi closed 1 year ago

tototoshi commented 1 year ago

Twirl has been generating code with Scala 2 syntax. Therefore, when compiling a Scala 3 project with the "-source:future" scalac option, the compilation would fail.

To address this issue, TwirlCompiler can now generate the appropriate code depending on the Scala version.

The Scala version is set by build tools. if you are using Maven or gradle, it will dynamically determine the Scala version you are currently using and set it. If you are using sbt, it will use the value of "scalaVersion". It can't dynamically determine the Scala version since the version for code generation (2.12.x, the runtime of sbt) and the version for compilation are different.

This fixes https://github.com/playframework/twirl/issues/591.