库有一个我从github克隆的示例项目。它是一个Java项目,使用Maven进行依赖项管理。我想在项目中添加一些Scala代码。我正在使用Eclipse Scala IDE。
答案 0 :(得分:0)
默认情况下,Maven不支持Scala,您需要启用scala-maven-plugin。这是我使用的pom.xml的<plugins>
部分中的配置:
<plugins>
<!-- other plugins ... -->
<!-- set scala plugin before compiler plugin -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scala.plugin.version}</version>
<configuration>
<recompileMode>incremental</recompileMode>
<javacArgs>
<javacArg>-Xlint:unchecked</javacArg>
<javacArg>-Xlint:deprecation</javacArg>
<javacArg>-encoding</javacArg>
<javacArg>${compiler.encoding}</javacArg>
</javacArgs>
</configuration>
<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>
之后,将您的Scala代码放在src/main/scala
文件夹中,并在src/test/scala
中进行测试,您应该没问题。
我认为当前的插件版本是3.2.1。这是指向official documentation的链接。