【问题标题】:Maven profiles in modules模块中的 Maven 配置文件
【发布时间】:2011-08-26 14:23:22
【问题描述】:

我有一个包含多个模块的 Maven Java EE 项目。

PROJECT
 --EJB
 --WEB1
 --WEB2
 --EAR

现在我想创建一个编译并包含 WEB1 的配置文件和一个包含两者的配置文件

为了从构建中排除/包含模块,我根据所选配置文件在主 pom.xml 中包含所需的子模块。这很好用。

问题在于 EAR 模块中的依赖关系。

如何排除模块 WEB1 或 WEB2。重新定义配置文件部分不起作用。

问题是:有没有办法根据选择的配置文件来控制项目模块中的依赖关系

编辑:

我的错,我在根目录中直接创建了标签

【问题讨论】:

    标签: maven


    【解决方案1】:

    无法根据配置文件排除模块,但包含适用于自 maven 3.0.2 以来的特殊功能“combine.children”的使用,如http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/ 中所述

    因此,您必须将 EAR 的最小内容定义为默认值,并使用配置文件在您的 ear 模块中按以下方式添加依赖项/模块:

    <project ....>
        ...
        <name>EAR</name>
        ...
        <dependencies>
            <dependency>EJB</dependency> // specify groupId, artifactId, version, type ...
            <dependency>WEB1</dependency>
        </dependencies>
        <profiles>
            <profile>
                <id>build-with-WEB2</id>
                <dependencies>
                    <dependency>WEB2</dependency> // specify groupId, artifactId, version, type ...
                </dependencies>
                <build>
                    <plugins>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-ear-plugin</artifactId>
                        <version>${maven-ear-plugin.version}</version>
                        <configuration>
                            <modules combine.children="append">
                                <webModule>
                                    <groupId>...</groupId>
                                    <artifactId>WEB2</artifactId>
                                    <bundleFileName>WEB2.war</bundleFileName>
                                    ...
                                </webModule>
                            </modules>
                        </configuration>
                    </plugins>
                </build>
            </profile>
        </profiles>
        <build>
            ...
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>${maven-ear-plugin.version}</version>
                    <configuration>
                        ...
                        <modules>
                            <ejbModule>
                                <groupId>...</groupId>
                                <artifactId>EJB</artifactId>
                                <bundleFileName>EJB.jar</bundleFileName>
                                ...
                            </ejbModule>
                            <webModule>
                                <groupId>...</groupId>
                                <artifactId>WEB1</artifactId>
                                <bundleFileName>WEB1.war</bundleFileName>
                                ...
                            </webModule>
                        </modules>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    【讨论】:

      猜你喜欢
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 2016-03-02
      • 1970-01-01
      • 2011-08-16
      • 2013-04-26
      相关资源
      最近更新 更多