gpt4 book ai didi

scala - 我的带有多模块项目的 scala-maven-plugin 配置不允许我在子目录中执行 'mvn compile'

转载 作者:行者123 更新时间:2023-12-04 14:48:19 26 4
gpt4 key购买 nike

我们将 scala-maven-plugin 用于我们的混合 Java/Scala 项目。总的来说效果很好,但是我们发现对于多模块项目,我们无法弄清楚如何在子目录中执行“mvn compile”。

我无法将我的完整源代码发布到 IP 限制,但在我搜索其他可能的项目时
已经解决了这个问题,我只设法提出了具有完全相同问题的其他项目。这是一个
例如:https://github.com/buildlackey/scala-multimodule-sample-project.git

上述项目在包含根 pom.xml 的目录下有三个子模块:cats、dogs 和 web-application。
如果你 git clone 上面的 url,然后 cd 到 'scala-multimodule-sample-project',你会看到它构建。
现在,如果我 cd 进入子模块“dogs”并执行“mvn compile”,我会看到以下消息:

[INFO] No sources to compile

但是有源编译!该插件只是没有找到它们。

这与我的多模块项目中发生的事情相同。我不能发布我们东西的全部来源.. 但是在这里
是我们顶级 pom.xml 中的相关配置:
<build>
<sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
<testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>

<!-- Compiling scala code -->
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<id>scala-compile</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>

根据插件的文档( http://davidb.github.io/scala-maven-plugin/add-source-mojo.html )
有一些可选参数可以传递给 add-source 目标:即 sourceDir 和 testSourceDir

但是,我不知道如何通过这些。也许这些参数是这里成功的关键?

最后,一种被证明成功的愚蠢解决方法是将 scala-maven-plugin 的相同配置复制到每个子模块目录中,我想在其中进行仅限于该子模块的编译。显然,这是一种非 DRY、不受欢迎的方法。

如果有人能提出一个好的解决方案,我将不胜感激。

谢谢 !

最佳答案

我在 https://github.com/davidB/scala-maven-plugin/tree/master/samples/prj_multi_modules 上传了一个工作示例

重复的解决方案是常见的用法。

DRY 替代方法是在 <pluginManagement> 中声明插件的配置。部分,然后在 <build><plugins><plugin> 下添加要启用插件的项目的 groupId + artifactId。您可以将其添加到 modules 的 pom.xml 或每个模块继承的 parent 的 pom.xml 中。
您也可以使用 <dependencyManagement>避免重复依赖的版本。
addSource是注册额外的源目录并将其公开给 IDE 和其他插件。

关于scala - 我的带有多模块项目的 scala-maven-plugin 配置不允许我在子目录中执行 'mvn compile',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34961137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com