gpt4 book ai didi

maven-2 - 是否可以覆盖父 POM 中已为配置文件定义的插件的配置?

转载 作者:行者123 更新时间:2023-12-03 04:49:09 26 4
gpt4 key购买 nike

在我的项目的 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)。

可能是什么问题?

澄清我的一些要求:

  • 我不想摆脱 parent POM 和配置文件 (wls7) 定义在里面(因为我需要很多很多属性、配置……)和这不是我的过程公司。
  • 基于复制的解决方案父 POM 和/或配置文件里面定义的不太好一。因为如果负责
    父 POM 改变了一些东西,我
    必须在我的报告中报告。

这只是一个继承问题(扩展或覆盖配置文件,来自上层 POM 的配置),所以我认为 Maven 2 应该可以实现。

最佳答案

可以通过将 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

关于maven-2 - 是否可以覆盖父 POM 中已为配置文件定义的插件的配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1771561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com