首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自pluginManagement的Maven插件继承

来自pluginManagement的Maven插件继承
EN

Stack Overflow用户
提问于 2013-08-07 21:00:24
回答 1查看 6.2K关注 0票数 3

那里

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

代码语言:javascript
复制
<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。

代码语言:javascript
复制
<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>

我的意图是在ear中包含所有3个jar文件-- artifact1、artifact2和artifact3。但是,在构建之后,只包含在子artifact3中定义的pom.xml。因此,在默认情况下,子<modules>中的pom.xml定义会覆盖父pom中定义的内容,而不是合并。实际上,如果我删除子<modules>中的整个pom.xml部分,则在构建之后将包含artifact1和artifact2。

我的问题是是否有一种方法包括在父pom和子pom中定义的所有jar模块。我有几个ear项目,它们都需要包含相同的jar模块集,加上自己的几个jar模块。我正在尝试将一组常见的jar模块移动到父程序中,这样它们就不会在每个子pom.xml中重复。

更新以澄清我的项目关系:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-07 21:39:58

为了实现合并行为,应该将maven-ear-plugin plugins标记放在父pom (而不是pluginManagement)中。

亲本pom

代码语言:javascript
复制
<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澄清的projects结构之后:在子项目中,modules元素上的属性modules

代码语言:javascript
复制
<modules combine.children="append">
    <jarModule>
        <groupId>com.test</groupId>
        <artifactId>artifact3</artifactId>
    </jarModule>
</modules>

父程序仍然应该只在pluginManagement中定义插件。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18113739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档