Upgrade project to Scala 2.13: JavaConversions is not a member of package collectio
Asked Answered
Q

1

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>
Quadriga answered 29/5, 2020 at 7:57 Comment(4)
Replace with import scala.jdk.CollectionConverters._Ugrian
@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.Quadriga
This plugin is outdated - author hasn't updated it for Scala 2.13 (see deps in mvnrepository.com/artifact/com.jakewharton.twirl/…). 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.Pugilist
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.Magnate
E
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

Eckert answered 16/6, 2020 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.