【问题标题】:Updating play framework project to Java 11 and cannot find correct dependency versions将 play framework 项目更新到 Java 11 并且找不到正确的依赖版本
【发布时间】:2020-05-22 17:27:31
【问题描述】:

将现有的 maven 项目从 Java 8 更新到 11,我正在努力寻找依赖项和插件版本的正确组合。 其中一个模块使用 play 框架及其相关依赖项,现在设置如下:

java: 11.0.5                    
scala: 2.12.8                   
sbt: 0.13.17                            
sbt-compiler-maven-plugin: 1.0.0        
sbtrun-maven-plugin: 1.0.1          
play: 2.6.21                    
play2-maven-plugin: 1.0.0-rc5
play2-provider-play26: 1.0.0-rc5        
akka: 2.5.27

这给了我以下构建错误:

[ERROR] Failed to execute goal com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-rc5:enhance (default-play2-enhance) on project services: Execution default-play2-enhance of goal com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-rc5:enhance failed: An API incompatibility was encountered while executing com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-rc5:enhance: java.lang.NoSuchMethodError: 'scala.collection.mutable.ArrayOps scala.Predef$.byteArrayOps(byte[])'
[ERROR] -----------------------------------------------------
[ERROR] realm =    extension>com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-rc5
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
...
...
...
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

注意:我希望将 akka 保持在 2.5.x 版本,因为 2.6.x 需要大量代码更改,但如有必要会转到更高版本

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>groupId</groupId>
        <artifactId>artifactId</artifactId>
        <version>version</version>
    </parent>
    <artifactId>artifactId</artifactId>
    <packaging>play2</packaging>
    <name>name</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <repositories>
        <repository>
            <id>typesafe</id>
            <url>http://repo.typesafe.com/typesafe/releases/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play_2.12</artifactId>
        </dependency>
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play-test_2.12</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play-java_2.12</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-joda</artifactId>
        </dependency>
        <dependency>
          <groupId>com.typesafe.akka</groupId>
          <artifactId>akka-stream_2.12</artifactId>
        </dependency>
        <dependency>
            <groupId>org.easytesting</groupId>
            <artifactId>fest-assert-core</artifactId>
        </dependency>
    </dependencies>
    <build>
        <!-- Play source directory -->
        <sourceDirectory>${basedir}/app</sourceDirectory>
        <testSourceDirectory>${basedir}/test</testSourceDirectory>
        <resources>
            <resource>
                <directory>${basedir}/conf</directory>
            </resource>
            <resource>
                <directory>${basedir}/public</directory>
                <targetPath>public</targetPath>
            </resource>
            <resource>
                <directory>${basedir}/target/sbt/web/public/main</directory>
                <targetPath>public</targetPath>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>com.google.code.play2-maven-plugin</groupId>
                <artifactId>play2-maven-plugin</artifactId>
                <version>1.0.0-rc5</version>
                <extensions>true</extensions>
                <configuration>
                    <mainLang>java</mainLang>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.google.code.play2-maven-plugin</groupId>
                        <artifactId>play2-provider-play27</artifactId>
                        <version>1.0.0-rc5</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>default-play2-enhance</id>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>dist</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.google.code.sbt-compiler-maven-plugin</groupId>
                <artifactId>sbt-compiler-maven-plugin</artifactId>
                <version>1.0.0</version>
            </plugin>

            <plugin>
                <groupId>com.google.code.sbtrun-maven-plugin</groupId>
                <artifactId>sbtrun-maven-plugin</artifactId>
                <version>1.0.1</version>
                <executions>
                    <execution>
                        <id>compile-assets</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <args>web-assets:assets</args>
                            <jvmArgs>-Dscala.version=2.12.8</jvmArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                </manifest>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.12</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- &lt;!&ndash; These empty tags keep IntelliJ quiet &ndash;&gt; -->
                    <name />
                    <regex />
                    <source />
                    <value />
                    <fileSet />
                    <artifacts>
                        <artifact>
                            <file>${project.build.directory}/service-${project.version}-dist.zip</file>
                            <type>zip</type>
                            <classifier>dist</classifier>
                        </artifact>
                    </artifacts>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>eclipse</id> <!-- for M2Eclipse only -->

            <build>
                <directory>${project.basedir}/target-eclipse</directory>

                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <skipMain>true</skipMain>
                            <skip>true</skip>
                            <source>11</source>
                            <target>11</target>
                        </configuration>
                        <executions>
                            <execution>
                                <id>default-compile</id>
                                <goals><goal>compile</goal></goals>
                            </execution>
                            <execution>
                                <id>default-testCompile</id>
                                <goals><goal>testCompile</goal></goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

编辑: 更新了 SBT 和 Scala 版本,添加了经过编辑的 pom

【问题讨论】:

    标签: scala playframework sbt akka java-11


    【解决方案1】:

    根据 scala 文档 https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html

    您的 SBT 版本与 Java 11 不兼容。我建议升级到 sbt.version=1.2.3

    如果您不想升级到更高版本,您正在使用的 Akka 版本应该是不错的。

    更新:

    我可以看到您将 sbt 版本更新到 0.13.17,并且您尝试使用更高版本,但是您应该忘记 sbt 0.13 并坚持使用 sbt 1.x,因为 sbt 0.13 使用的是 scala 2.10 和 sbt 1.x scala 2.12。

    我还注意到您没有 maven-compiler-plugin 的版本标记。如果你使用的是 maven 3,它应该会因为缺少这个标签而无法构建,因为它不是,我猜你使用的是应该升级的 maven 2。您还应该将 3.8.0 版本标记添加到 maven-compiler-plugin。

    检查this guide 以了解如何为 java 11 正确配置此插件。您还应该检查其他说明以查看是否所有配置都正确。

    【讨论】:

    • 感谢您的回复,抱歉最初的问题是 SBT 版本的拼写错误,我已经使用 JDK 11 推荐的 0.13.17 和 1.1.0 版本(现在也是 1.2. 3)但仍然没有运气
    • 我怀疑您的问题与您的 Maven 配置有关。你能发布你的maven配置吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 2013-10-03
    • 2015-04-16
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多