在我的项目的POM父文件中,我有一个这样的配置文件定义了一些对这个项目有用的配置(这样我就无法摆脱这个父POM):
<profile>
<id>wls7</id>
...
<build>
<plugins>
<!-- use java 1.4 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<source>1.4</source>
<target>1.4</target>
<meminitial>128m</meminitial>
<maxmem>1024m</maxmem>
<executable>%${jdk14.executable}</executable>
</configuration>
</plugin>
</plugins>
</build>
...
</profile>
但在我的项目中,我只想覆盖maven-compiler-plugin的配置,以便使用jdk5而不是jdk4来编译测试类。
这就是我在项目的POM中完成此部分的原因:
<profiles>
<profile>
<id>wls7</id>
<activation>
<property>
<name>jdk</name>
<value>4</value>
</property>
</activation>
<build>
<directory>target-1.4</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>my-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<fork>true</fork>
<executable>${jdk15.executable}</executable>
<compilerVersion>1.5</compilerVersion>
<source>1.5</source>
<target>1.5</target>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
...
</profiles>
它不起作用......
我甚至尝试覆盖POM的常规插件部分中的配置(我的意思是,不是针对特定的配置文件,而是针对我的整个POM)。
可能是什么问题?
澄清我的一些要求:
这只是一个继承问题(扩展或覆盖配置文件,来自上层POM的配置)所以我认为应该可以使用Maven 2。
答案 0 :(得分:127)
通过将combine.self="override"
属性添加到pom中的元素,可以覆盖父pom中的配置。
尝试将插件配置更改为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>my-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration combine.self="override">
<fork>true</fork>
<executable>${jdk15.executable}</executable>
<compilerVersion>1.5</compilerVersion>
<source>1.5</source>
<target>1.5</target>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
有关覆盖插件的详细信息,请参阅:http://maven.apache.org/pom.html
答案 1 :(得分:4)
为了解决这个问题,我传入了combine.self属性并且工作正常。
默认构建:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<packagingExcludes>swagger-ui/client.html</packagingExcludes>
</configuration>
</plugin>
验收测试资料:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration combine.self="override"/>
</plugin>
答案 2 :(得分:1)
您是否尝试停用wls7配置文件(自maven 2.0.10起):
从Maven 2.0.10开始,一个或 可以使用停用更多配置文件 命令行通过添加前缀 带有字符的标识符 '!'或' - '如下所示:
mvn groupId:artifactId:goal -P !profile-1,!profile-2
这可用于停用 标记为activeByDefault或的配置文件 否则将会是个人资料 通过激活激活 配置。
然后在具有不同名称的个人资料中添加您的配置,或直接在pom.xml
。