是否可以覆盖已经为父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>
它不起作用...
我什至试图覆盖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有所更改,我
将不得不在我的报告.
- I don't want to get rid of the parent POM and the profile (wls7) defined inside it (since I need many and many properties, configurations, ...) and that is not the process in my company.
- A solution based on duplicating
the parent POM and/or the profile
defined inside it is not a good
one. Since if the responsible of
the parent POM change something, I
would have to report it in mine.
这只是一个继承问题(扩展或覆盖配置文件,即来自上层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.
推荐答案
可以通过将combine.self="override"
属性添加到pom中的元素来完成从父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屋!