我的混合 Scala/Java Maven 项目无法编译
我有一个混合的Scala/Java项目,编译不好。
当Java代码尝试在同一包中调用Scala代码时,问题就出现了。
当然,我有标准的布局:
- src/main/java
- src/main/scala
- src/test/java
- src/test/scala
我看过其他类似的Stackoverflow问题,但这个问题有点过时了。另一个问题也无济于事。
我也关注了 scala-maven-plugin 文档页面。
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我试图关注这篇博客文章,但没有成功。
带有从pom导入的Scala插件的IDEA项目.xml可以成功编译并运行我的项目。
正确的方法是什么?Java代码是否被编译了两次?首先是Scala插件和Java插件?。