问题描述
我在多模块maven项目中使用了maven-enforcer插件。假设我的项目结构如下所示
main
- query
- storage
我在main
pom中的执行程序插件如下所示
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>default</id>
<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>
</executions>
</plugin>
</builds>
在子模块(query
中,如果我需要禁用其中一个执行器规则(例如DependencyConvergence
),有人可以让我知道如何执行吗?
Maven版本-3.6.1
解决方法
FAIK,您不能禁用一个强制规则。
您可以将enforcer.skip
设置为true
-这将禁用所有强制规则。
在类似情况下我做了什么:
我已经定义了自己的强制规则,该规则继承自“官方”强制规则。该执行器规则包含一个禁用它的开关。
,在maven mailing list中也会回答。
因此,如果所有配置都是通过 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>
您也可以通过属性来执行此操作,并在查询中定义 勇敢地执行而不是Alpha。我用过类似的技术 使用maven-surefire-plugin,其中我使用 属性,并且在根/父pom和一个 特定的子pom我定义了一个不同的surefire版本。所以这 可能有用...
<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> </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>
约翰