原因:项目打包时,会先编译java代码,再编译scala代码。编译顺序有问题导致打包时找不到相应的scala 类

解决:添加一个Maven build的插件

<plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>compile-scala</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scalaVersion>2.11.8</scalaVersion>
                </configuration>
            </plugin>

最重要的一段

<executions>
                    <execution>
                        <id>compile-scala</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>

相关文章:

  • 2022-12-23
  • 2021-11-07
  • 2021-07-31
  • 2022-12-23
  • 2022-02-21
  • 2021-05-17
  • 2021-07-30
  • 2021-09-16
猜你喜欢
  • 2022-01-03
  • 2022-12-23
  • 2021-08-20
  • 2021-05-27
  • 2022-02-26
  • 2021-12-20
  • 2022-12-23
相关资源
相似解决方案