如何通过pom.xml将maven "--also-make"选项传递到命令行



假设有一个父项目a的pom.xml中有模块B和C。

Project A
|-pom.xml
|----------->ModuleB
|               |->pom.xml
|----------->ModuleC
|               |->pom.xml
<modules>
<module>B</module>
<module>C</module>
</modules>

模块C本身具有一些仅属于该子模块的依赖关系。这个依赖关系应该在模块C之前构建,所以当为C调用"mvn-install"时,我想调用"-am"(--also-make(选项。

Maven正在远程执行,我只有pom文件。构建作业在远程Jenkins上运行,它使用项目A父pom中的当前配置文件,只能使用此配置文件。

我认为它可以在模块C的pom中完成,例如在maven编译器插件的配置中?

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.source}</source>
<target>${jdk.target}</target>
**<arguments>-am</arguments>** <!--smth like this maybe?-->
</configuration>
</plugin>

我还想过创建另一个pom.xml,以正确的顺序只有子模块C及其依赖项,并在父pom中使用它来代替当前的子模块C,但我想先尝试-am选项。此外,我现在不太明白该把这个新pom放在哪里,因为我们已经达到了A级。

也许整个项目结构应该重构,但这正是我目前所拥有的。

Upd:以下是简化程度较低的当前项目结构。

Project A (maven parent for B, C, D)
|-pom.xml
|----------->ModuleB
|               |->pom.xml
|----------->folder
|----------->folder
|----------->ModuleC
|               |->pom.xml
|----------->ModuleD
|               |->pom.xml
<modules>
<module>B</module>
<!-- <module>D</module> | initially was here, now needs to be only C's dependency -->
<module>C</module>
</modules>

当指定的项目也列在聚合器(reactor(pom.xml的模块部分时,也可以使用make选项。由于模块部分没有所需的项目,因此无法在当前设置中使用它。

你只需将额外的项目添加到你当前的模块部分,这将解决你的问题。(你不必担心你编写的模块的顺序,Maven会按照正确的顺序为你构建它们。你也不必使用make(

您也可以使用您在问题中建议的解决方案。它不必是C的父级,它可以只是C及其依赖项的聚合器。(我认为这没有必要。你可以把它们全部添加到你当前的模块部分(

父pom和聚合器pom也是不同的概念。

最新更新