playframework / twirl

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

Scala 2.13 support #414

Closed sashaepstein closed 3 years ago

sashaepstein commented 3 years ago

Greetings!

Looking at the plugin project's build.sbt is seems that it will use Scala 2.12. Is there a possibility to use this plugin for Scala 2.13? I found this useJavaHelpers workaround for Maven twirl plugin for Scala 2.13:

                    <groupId>com.jakewharton.twirl</groupId>
                    <artifactId>twirl-maven-plugin</artifactId>
                    <version>1.2.0</version>
                    <configuration>
                        <useJavaHelpers>false</useJavaHelpers>
                    </configuration>

Maybe there is something similar for sbt plugin?

Thanks!

SethTisue commented 3 years ago

Twirl definitely supports Scala 2.13.

As for what you're seeing in the build for the Twirl sbt plugin, note that sbt 1.x uses Scala 2.12 internally. All sbt 1 build definitions are Scala 2.12 code. Every sbt plugin is a Scala 2.12 project. Regardless, sbt 1 is of course fully capable of building projects written in Scala 2.11, 2.12, 2.13, 3, you name it.

In short, I don't think there is any issue here. Have you actually tried using Twirl in 2.13 project? Try it — let us know if you experience some specific difficulty.

sashaepstein commented 3 years ago

Thanks, Seth, for clarification on sbt plugins build environment. The problem is that Scala templates produced by sbt twirl plugin contain imports deprecated in Scala 2.13, like: /*7.2*/import scala.collection.JavaConverters._ even though they are not used in the compiled code. The maven plugin configuration useJavaHelpers=false disables inclusion of those imports, and I am looking for something similar in sbt twirl plugin.

sashaepstein commented 3 years ago

Sorry, that was a wrong example. I modified that template to replace all Java collections with Scala collections and I don't see import of JavaConvertes anymore. So let's close this issue. Once I am ready to upgrade our project to Scala 2.13 and find any issues I will let you know. Thanks for your support!

SethTisue commented 3 years ago

It appears to me that those imports are specific to the Maven plugin: https://github.com/JakeWharton/twirl-maven-plugin/blob/fdbfe7c70b19ae08ef132fc5108fda366947d4eb/twirl-maven-plugin/src/main/java/com/jakewharton/twirl/CompileMojo.java#L41-L46