问题描述:java、scala混用的情况下,maven打包,遇到找不到符号的报错。
原因:若在java代码中调用了scala代码,则需先编译scala代码,后编译java代码。
解决方案 :
解决方案1:
参考1:https://blog.csdn.net/ilvchocolate/article/details/75626921
第一步:
mvn clean scala:compile compile
第二步:
mvn package
解决方案2:
上文参考的pom.xml的build无效,故贴上我测试后可用的插件配置
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>compile-scala</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile-scala</id>
<phase>test-compile</phase>
<goals>
<goal>add-source</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>2.11.0</scalaVersion>
<recompileMode>incremental</recompileMode>
<args>
<arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
</args>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<id>compile-scala</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
网友评论