问题描述
当我编译 Scala 源时,此pom.xml
的工作原理是:
<build>
<sourceDirectory>${project.basedir}/src/main/scala</sourceDirectory>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.4.0</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
[...]
但不是这种选择:
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.4.0</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDir>${project.basedir}/src/main/scala</sourceDir>
<testSourceDir>${project.basedir}/src/test/scala</testSourceDir>
</configuration>
</execution>
[...]
即使在plugin documentation中为此用途提到了sourceDir
和testSourceDir
。
我需要第二种选择,因为在执行此操作之后,将调用依赖于其他源文件目录的 Java 编译器。
我也尝试了致电add-source
目标。没有成功。
解决方法
您尝试用错误的方法替代配置,我想${project.basedir}
并没有被期望值取代。
您想要的是默认行为,因此您只需删除覆盖
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.4.0</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
更新:检查日志(输出)以查看插件扫描要编译的文件夹。