让我们考虑以下父POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>imaginary-plugin</artifactId>
<version>1.0</version>
<configuration>
<whatever>111</whatever>
</configuration>
<inherited>false</inherited>
</plugin>
<plugin>
<groupId>com.example</groupId>
<artifactId>imaginary-plugin-exec</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>whatever</id>
<goals>
<goal>whatever</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
<configuration>
<whatever>111</whatever>
</configuration>
<inherited>false</inherited>
</plugin>
</plugins>
</pluginManagement>
<!-- same as above, for the sake of example -->
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>imaginary-plugin</artifactId>
<version>1.0</version>
<configuration>
<whatever>111</whatever>
</configuration>
</plugin>
<plugin>
<groupId>com.example</groupId>
<artifactId>imaginary-plugin-exec</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>whatever</id>
<goals>
<goal>whatever</goal>
</goals>
</execution>
</executions>
<configuration>
<whatever>111</whatever>
</configuration>
<inherited>false</inherited>
</plugin>
</plugins>
</build>
</project>
我们有两个不存在的插件,其中一个(imaginary-plugin-exec
(的执行定义了
现在让我们添加一个子POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<artifactId>child</artifactId>
</project>
当我们得到孩子的有效POM(mvn help:effective-pom
(时,我们得到以下pluginManagement
和plugins
:
<pluginManagement>
<plugins>
<!-- a bunch of default plugin configs, skipped for clarity -->
<plugin>
<groupId>com.example</groupId>
<artifactId>imaginary-plugin-exec</artifactId>
<version>1.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>imaginary-plugin-exec</artifactId>
<version>1.0</version>
</plugin>
<!-- a bunch of default plugin configs, skipped for clarity -->
</plugins>
正如我们所看到的,imaginary-plugin-exec
出现在有效的POM中,即使它在父POM中继承了设置为false。然而,它没有任何配置(因此禁用继承部分有效(。这种行为的原因是什么?有办法避免吗?
为了解决这个问题,我尝试设置<inherited>false</inherited>
执行,但没有帮助。
<inherited>
元素的描述说:
是否应将任何配置传播到子POM。
页面上可以找到相同的信息,措辞略有不同,这意味着<inherited>
只能用于停止插件配置的继承,而不能用于插件本身。