将 -f 选项引入多模块

发布于 2025-01-06 15:05:43 字数 515 浏览 3 评论 0原文

maven 中有 -f 选项,允许指定备用 pom.xml 文件。我是否有可能也可以将此行为带到执行的模块中?现在看起来,当我有这个结构时:

projectA: pom.xml pom.xml2
projectB: pom.xml pom.xml2
And when I run maven with -f pom.xml2 option as reactor with projectB specified as module, it looks like that it picks pom.xml2 from the projectA, and it picks pom.xml from projectB. Is there a way, how can I propagate the -f option to the modules?
Thanks for answering.

there is -f option in maven, that allows to specify alternate pom.xml file. Is there a possibility, that I can also bring this behaviour to the executed modules? Now it looks like, that when I have this structure:

projectA: pom.xml pom.xml2
projectB: pom.xml pom.xml2

And when I run maven with -f pom.xml2 option as reactor with projectB specified as module, it looks like that it picks pom.xml2 from the projectA, and it picks pom.xml from projectB. Is there a way, how can I propagate the -f option to the modules?
Thanks for answering.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸印温柔 2025-01-13 15:05:43

因为我们可以在模块定义中指定pom文件。1
这是在模块中使用替代 pom 文件的示例。

<modules>
    <module>child1/pom-jdk14.xml</module>
    <module>child2/pom-jdk14.xml</module>
</modules>

Because we can specified pom file in module definition.1
Here's an example for using alternative pom file in module.

<modules>
    <module>child1/pom-jdk14.xml</module>
    <module>child2/pom-jdk14.xml</module>
</modules>
栖竹 2025-01-13 15:05:43

正如 Jörn Horstmann 评论的那样,我会尝试很多方法来在一个 pom 中使用配置文件。

如果这不可能,我能想到的唯一方法是通过使用带有配置文件的“switching pom”来绕过正常的 Maven 机制。这个pom作为pom.xml放在每个模块中,并为每个pom.xml2(或其他)都有一个配置文件,并在该配置文件中通过antrun-plugin执行另一个maven构建fe,并为您需要的pom使用-f:

<profile>
            <id>xml2</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>build pom.xml2</id>
                                <phase>prepare-package</phase> <!-- whatever suits you -->
                                <configuration>
                                    <target>
                                                <echo level="info" message="Building pom.xml2..." />
                                                <exec executable="cmd" dir=".">
                                                    <arg value="/c" />
                                                    <arg value="mvn" />
                                                    <arg value="-f" />
                                                    <arg value="pom.xml2" />
                                                    <arg value="install" /> <!-- enter which phase you need -->
                                                </exec>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

As Jörn Horstmann comments I would try lots of things to get this working with profiles in one pom.

If that's not possible the only way I can think of to get this working is to bypass the normal maven mechanism by using a "switching pom" with profiles. This pom is put as pom.xml in each module and has a profile for each of your pom.xml2 (or others) and in that profile executes another maven build f.e. via the antrun-plugin with the -f for the pom you need:

<profile>
            <id>xml2</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>build pom.xml2</id>
                                <phase>prepare-package</phase> <!-- whatever suits you -->
                                <configuration>
                                    <target>
                                                <echo level="info" message="Building pom.xml2..." />
                                                <exec executable="cmd" dir=".">
                                                    <arg value="/c" />
                                                    <arg value="mvn" />
                                                    <arg value="-f" />
                                                    <arg value="pom.xml2" />
                                                    <arg value="install" /> <!-- enter which phase you need -->
                                                </exec>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文