Maven:可以覆盖已经为父POM中的配置文件定义的插件的配置 [英] Maven : Is it possible to override the configuration of a plugin already defined for a profile in a parent POM
问题描述
在我的项目的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-编译器插件的配置使用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>
< / goal>
< 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和配置文件(wls7)定义
里面(因为我需要许多和许多
属性,配置...)和
- 基于重复
的解决方案,父POM和/或其中定义的配置文件
不是一个好
一。因为如果负责人
的父POM改变了东西,我
必须在我的报告。
这只是一个继承的事情(扩展或覆盖配置文件,从上级POM的配置)所以我认为应该可以用maven2。
通过将 combine.self =override
属性添加到父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>
< / goal>
< 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
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>
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.
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 ...
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).
What could be the problem ?
To clarify some of my requirements :
- 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.
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 maven2.
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>
For more information on overriding plugins, see: http://maven.apache.org/pom.html
这篇关于Maven:可以覆盖已经为父POM中的配置文件定义的插件的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!