我有以下(单个)scala 类
[ 14253 Oct 30 8:44] ./pom.xml
[ 9083 Oct 30 8:30] ./scaladem.iml
[ 102 Oct 29 19:21] ./src
[ 102 Oct 29 19:21] ./src/main
[ 102 Oct 29 19:21] ./src/main/scala
[ 102 Oct 29 19:21] ./src/main/scala/com
[ 102 Oct 29 19:21] ./src/main/scala/com/blazedb
[ 102 Oct 30 8:30] ./src/main/scala/com/blazedb/scalademo
[ 4646 Oct 30 8:30] ./src/main/scala/com/blazedb/scalademo/SDemo.scala
这是pom的适用部分
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<configuration>
<recompileMode>incremental</recompileMode>
<javacArgs>
<javacArg>-Xlint:unchecked</javacArg>
<javacArg>-Xlint:deprecation</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>
当我们跑
mvn compile
我们得到(注意'没有来源'..)
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SDemo 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ scalademo ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
更新:运行以下命令时
$mvn scala:compile -DdisplayCmd=true
编译成功。
根据@badtrumpet 的建议,我添加了如下所示的显式
<sourceDirectory>src/main/scala</sourceDirectory>
这甚至可以通过 mvn compile 进行。但这对于混合 java/scala 项目来说将是一个问题。