这也在maven 邮件列表中得到了回答。
因此,如果所有配置都通过 pluginMangement 部分管理,则类似于以下内容;
<build><pluginManagement><plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>alpha</id>
<phase></phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<DependencyConvergence/>
<requireJavaVersion>
<version>[1.8,)</version>
<message>*** This project requires
JDK 1.8/J2SE 8 or later. ***</message>
</requireJavaVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
<execution>
<id>bravo</id>
<phase></phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8,)</version>
<message>*** This project requires
JDK 1.8/J2SE 8 or later. ***</message>
</requireJavaVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>alpha</id>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins></builds>
query/pom.xml
<build><plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>alpha</id>
<phase></phase>
</execution>
<execution>
<id>bravo</id>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</executions>
</plugin>
</plugins></builds>
你也可以通过一个属性来做到这一点,并在查询中定义 bravo 执行而不是 alpha。我在 maven-surefire-plugin 中使用了类似的技术,在其中我使用属性定义插件版本并在根/父 pom 中具有默认值,并且在一个特定的子 pom 中我定义了不同的肯定版本。所以这可能工作......
<build><pluginManagement><plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>alpha</id>
<phase></phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<DependencyConvergence/>
<requireJavaVersion>
<version>[1.8,)</version>
<message>*** This project requires
JDK 1.8/J2SE 8 or later. ***</message>
</requireJavaVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
<execution>
<id>bravo</id>
<phase></phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8,)</version>
<message>*** This project requires
JDK 1.8/J2SE 8 or later. ***</message>
</requireJavaVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>${which-enforcer-id}</id>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins></builds>
<properties>
<which-enforcer-id>alpha</which-enforcer-id>
</properties>
query/pom.xml
<properties>
<which-enforcer-id>bravo</which-enforcer-id>
</properties>
约翰