gpt4 book ai didi

Maven 插件继承自 pluginManagement

转载 作者:行者123 更新时间:2023-12-05 01:21:35 25 4
gpt4 key购买 nike

那里

我有一个父 pom.xml,它定义了 maven-ear-plugin 的默认配置

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<modules>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact1</artifactId>
</jarModule>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact2</artifactId>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>

在子 pom 中,我在 <plugins> 中定义了 maven-ear-plugin节

<plugin>
<artifactId>maven-ear-plugin</artifactId>
<executions>
<execution>
<id>default-ear</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<earSourceDirectory>EarContent</earSourceDirectory>
<defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
<modules>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact3</artifactId>
</jarModule>
</modules>
</configuration>
</execution>
</executions>
</plugin>

我的意图是将所有 3 个 jar 文件 artifact1、artifact2 和 artifact3 包含在 ear 中。但是,在构建之后,仅包含子 pom.xml 中定义的 artifact3。所以默认情况下看起来像<modules>子 pom.xml 中的定义会覆盖父 pom 中定义的内容,而不是将它们合并 在一起。事实上,如果我删除整个 <modules>在子 pom.xml 部分中,artifact1 和 artifact2 将在构建后包含在内。

我的问题是是否有办法包含父 pom 和子 pom 中定义的所有 jar 模块。我有几个 ear 项目,它们都需要包含相同的 jar 模块集以及一些它们自己的 jar 模块。我正在尝试将通用的 jar 模块集移动到父级,以便它们不会在每个子级 pom.xml 中重复。

更新以阐明我的项目关系:

parent pom.xml (define maven-ear-plugin in the pluginManagement section)
-- project1 pom.xml (multi-module project)
-- myJar-proj1
-- myWeb-proj1
-- myEar-proj1 (define maven-ear-plugin in the <build> section)
-- project2 pom.xml (multi-module project)
-- myJar-proj2
-- myWeb-proj2
-- myEar-proj2 (define maven-ear-plugin in the <build> section)

最佳答案

为了实现合并行为,您应该放置 maven-ear-plugin under the pluginspom 中的标记(而不是 under pluginManagement )。

pom:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<modules>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact1</artifactId>
</jarModule>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact2</artifactId>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>

编辑

在 OP 阐明了项目结构之后:modules 元素上的属性 combine.children="append",在子项目中:

<modules combine.children="append">
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact3</artifactId>
</jarModule>
</modules>

父级仍应仅在 pluginManagement 中定义插件。

关于Maven 插件继承自 pluginManagement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18113739/

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