是否可以覆盖已为父 POM 中的配置文件定义的插件的配置? [英] Is it possible to override the configuration of a plugin already defined for a profile in a parent POM?
问题描述
在我的项目的 POM 父文件中,我有这样一个配置文件,定义了一些对这个项目有用的配置(这样我就无法摆脱这个父 POM):
In a POM parent file of my project, I have such a profile defining some configurations useful for this project (so that I can't get rid of this parent 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 来编译测试类.
But in my project I just would like to override the configuration of the maven-compiler-plugin in order to use jdk5 instead of jdk4 for compiling test-classes.
这就是为什么我在我的项目的 POM 中做了这个部分:
That's why I did this section in the POM of my project :
<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>
它不起作用......
and it's not working ...
我什至尝试覆盖 POM 的常规插件部分中的配置(我的意思是,不是针对特定配置文件,而是针对我的整个 POM).
I even tried to override the configuration in regular plugin sections of my POM (I mean, not for a specific profile but for my whole POM).
可能是什么问题?
澄清我的一些要求:
- 我不想摆脱父级POM 和配置文件 (wls7) 定义在里面(因为我需要很多很多属性,配置,...)和这不是我的过程公司.
- 基于复制的解决方案父 POM 和/或配置文件里面定义的不好一.自如果负责
父 POM 改变了一些东西,我
必须向我报告.
这只是一个继承问题(扩展或覆盖配置文件,来自上层 POM 的配置)所以我认为 Maven 2 应该是可能的.
It's just an inheritance matter (extend or override a profile, a configuration from an upper-level POM) so I think it should be possible with Maven 2.
推荐答案
可以通过向 pom 中的元素添加 combine.self="override"
属性来覆盖父 pom 的配置.
Overriding configurations from a parent pom can be done by adding the combine.self="override"
attribute to the element in your pom.
尝试将您的插件配置更改为:
Try changing your plugin configuration to:
<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
For more information on overriding plugins, see: http://maven.apache.org/pom.html
这篇关于是否可以覆盖已为父 POM 中的配置文件定义的插件的配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!