我有两个几乎相同的配置文件。不想在每个文件中都重复配置,希望一个配置文件能够从另一个配置文件中"继承",但是我在使用Maven 3时没有找到明显的方法来实现这一点。
在Maven中是否支持配置文件的继承?
我有两个几乎相同的配置文件。不想在每个文件中都重复配置,希望一个配置文件能够从另一个配置文件中"继承",但是我在使用Maven 3时没有找到明显的方法来实现这一点。
在Maven中是否支持配置文件的继承?
不可以继承配置文件。
但是,你可以拥有多个活动配置文件,通过将两个配置文件中的共同元素拆分成第三个配置文件,并在激活其他两个配置文件时同时激活该配置文件,从而实现大致相同的效果。
严格来说,按照Maven文档的规定,父pom中定义的profile不能在子pom中继承。然而,父pom中指定的属性和构建插件(不包括pluginManagement)可以被激活并修改子pom的构建环境。 例如,如果我有一个名为A的父pom,其中具有以下配置文件部分:
</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,在默认构建中未配置failsafe插件,但通过parent标签继承自A pom。如果我从子pom目录中运行“mvn clean install -P integrationTest”,它将使用在A中指定的插件信息。
-P profile1,commonProfile
?还是有一种方法可以配置一个配置文件来激活另一个配置文件?文档只提到创建额外的属性并在<activation>
中使用它们。 - jmmut