【问题标题】:Can a maven profile inherit from another maven profile?一个 Maven 配置文件可以从另一个 Maven 配置文件继承吗?
【发布时间】:2011-12-26 10:47:45
【问题描述】:

我有两个几乎相同的个人资料。我不想在每个配置文件中复制配置,而是希望一个配置文件从另一个配置文件“继承”,但我没有看到使用 maven 3 的明显方法。

在 maven 中是否可以继承配置文件?

【问题讨论】:

    标签: maven


    【解决方案1】:

    不,配置文件不能被继承。

    但是,您可以拥有多个活动配置文件,通过将两个配置文件中的公共元素分解到第三个配置文件中,您可以在激活其他两个配置文件之一时激活该配置文件,从而完成大致相同的事情。

    【讨论】:

    • > 激活其他两个配置文件之一时激活的第三个配置文件。你的意思是手动激活两者?比如说-P profile1,commonProfile?或者有没有办法配置一个配置文件来激活另一个配置文件? documentation 只提到创建额外的属性并在<activation> 中使用它们。
    • 另请注意,当多个不同的活动弹簧配置文件在多个 maven 配置文件中定义,然后一起使用时,可能会出现问题:(stackoverflow.com/questions/51556593/…
    【解决方案2】:

    根据 maven 文档,严格来说,配置文件不会被继承,因为父 pom 中定义的配置文件在子 pom 中不可用。但是,在父 pom 中指定的属性和构建插件(不是 pluginManagement)可以被激活,从而修改子 pom 的构建环境。 例如,如果我有一个父 pom A,它具有以下配置文件部分:

      </profiles>
          <profile>
                <id>integrationTest</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                <parallel>none</parallel>
                                <excludes>
                                    <exclude>**/*Test.java</exclude>
                                </excludes>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <configuration>
                                <includes
                                    <include>**/*IT.java</include>
                                </includes>
                                <!-- need to exclude nothing as it is possible that some by default some tests are excluded and we need to override that -->
                                <excludes>
                                    <exclude>none</exclude>
                                </excludes>
                                <parallel>none</parallel>
                            </configuration>
                        </plugin>            
                    </plugins>
                </build>
            </profile>
       </profiles>
    

    然后是一个子 pom B,它没有在默认构建中配置故障安全插件,但通过父标签从 A pom 继承,然后我从子 pom 目录运行“mvn clean install -P integrationTest”,它将取A中指定的插件信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-30
      • 2010-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      相关资源
      最近更新 更多