繁体   English   中英

如何通过pom.xml将Maven“ --also-make”选项传递给命令行

[英]How to pass maven “--also-make” option via pom.xml to command line

假设有一个父项目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-compiler-plugin的配置中?

    <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级。

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

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

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>

当指定的项目也在a聚合器(reactor)pom.xml的模块部分中列出时,可以使用--also-make选项。 由于您的模块部分中没有必需的项目,因此您不能在当前设置中使用它。

您可以将额外的项目添加到当前模块部分,这将解决您的问题。 (您不必担心所编写模块的顺序,Maven会按照您的正确顺序来构建它们。而且您不必使用Also-make)

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM