4

I want to upgrade Scala version in multimodule maven project from 2.11 to 2.13. I changed all Scala version and Scala suffix version in pom.xml, updated the dependency version. I got next error in compilation:

 \target\generated-sources\twirl\txt\template.template.scala:12: object JavaConversions is not a member of package collection

In target folder I found compiled object of twirl template:

import _root_.play.twirl.api.JavaScript
import _root_.play.twirl.api.Xml
....
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._

object analyze_template extends _root_.play.twirl.api.BaseScalaTemplate[pla

From twirl template:

@(sourceIncrementName: String, sourceSnapshotName: String)

Could you tell me how to resolve it?

In maven I have scala-maven-plugin and twirl plugin:

            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <jvmArgs>
                        <jvmArg>-Xms128m</jvmArg>
                        <jvmArg>-Xmx1024m</jvmArg>
                        <jvmArg>-XX:MaxPermSize=512m</jvmArg>
                    </jvmArgs>
                    <args>
                        <arg>-unchecked</arg>
                        <arg>-deprecation</arg>
                        <arg>-explaintypes</arg>
                        <arg>-feature</arg>
                        <arg>-language:implicitConversions</arg>
                    </args>
                    <recompileMode>incremental</recompileMode>
                    <scalaVersion>2.13</scalaVersion>
                </configuration>
            </plugin>
       <plugin>
           <groupId>com.jakewharton.twirl</groupId>
           <artifactId>twirl-maven-plugin</artifactId>
           <version>1.1.0</version>
           <executions>
               <execution>
                   <phase>generate-sources</phase>
                   <goals>
                       <goal>compile</goal>
                   </goals>
               </execution>
           </executions>
       </plugin>

And twirl dependency:

    <dependency>
        <groupId>com.typesafe.play</groupId>
        <artifactId>twirl-api_2.13</artifactId>
    </dependency>
Vadim
  • 753
  • 8
  • 22
  • 3
    Replace with `import scala.jdk.CollectionConverters._` – Mario Galic May 29 '20 at 08:32
  • @MarioGalic Thank you for response but I cant replace it because file with imports JavaConversions is in folder target/generated-sources. And recompile every times. – Vadim May 29 '20 at 09:09
  • 1
    This plugin is outdated - author hasn't updated it for Scala 2.13 (see deps in https://mvnrepository.com/artifact/com.jakewharton.twirl/twirl-maven-plugin/1.2.0). So you have to fork and update it, or change the build tool, or write your own plugin which would hook after source code generation to edit the sources. – Mateusz Kubuszok May 29 '20 at 09:44
  • 2
    The use of `JavaConversions` was always a bad idea and discouraged, they were deprecated on `2.12` and finally removed on `2.13`. If this code is autogenerated, you simply can not upgrade until the plugin fixes this error, you may want to open an issue _(or maybe a PR)_ on the original project. – Luis Miguel Mejía Suárez May 29 '20 at 13:11

1 Answers1

5

As of Scala 2.13, the object JavaConverters in scala.collection package has been deprecated. You have to use scala.jdk.CollectionConverters henceforth. You can find the full documentation here

Yayati Sule
  • 1,601
  • 13
  • 25