Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip module with Maven enforcer

I'm using enforcer plugin in a multi-node project in the root pom, but I have one testing module, that I don't really care to run the plugin there since it won't create any jar and is only for testing purposes. Is there any way to skip one of the modules in the plugin config?.

Checking the documentation I cannot find anything. Only how to ban some specific dependencies. https://maven.apache.org/enforcer/enforcer-rules/bannedDependencies.html

The solution to put the plugin in each sub-module is possible but it's dangerous, since if I create a new sub-module I might forget to add it there.

Here my plugin config.

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-enforcer-plugin</artifactId>
          <version>3.0.0-M3</version>
          <executions>
            <execution>
              <id>enforce-maven-version-and-dependencies</id>
              <goals>
                <goal>enforce</goal>
              </goals>
              <configuration>
                <rules>
                  <requireMavenVersion>
                    <version>3.3.9</version>
                  </requireMavenVersion>
                  <bannedDependencies>
                    <searchTransitive>true</searchTransitive>
                  </bannedDependencies>
                  <dependencyConvergence></dependencyConvergence>
                </rules>
              </configuration>
            </execution>
          </executions>
          <configuration>
            <fail>true</fail>
          </configuration>
        </plugin>
like image 509
paul Avatar asked May 21 '20 17:05

paul


People also ask

What is the use of Maven enforcer plugin?

The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family along with many more built-in rules and user created rules.

What is banned dependency in Maven?

This rule checks the dependencies and fails if any of the matching excludes are found. The following parameters are supported by this rule: searchTransitive - if transitive dependencies should be checked.

What is the use of enforcer in Maven?

Maven Enforcer has two goals: enforcer:enforce and enforcer:display-info. The enforce goal runs during a project build to execute rules specified in the configuration, while the display-info goal shows current information about the built-in rules that are present in the project's pom.xml.

How to skip tests in Maven?

Similarly maven.test.skip, you can define system property skipTests from command line or in pom.xml. Results: Only skips running tests, and Copying test resources, Compiling test sources phase will not be skipped. To not skip tests, use command $ mvn clean package -DskipTests=false. 3. Maven surefire plugin

What is display-info goal in Maven enforcer?

Plugin Configuration and Goals Maven Enforcer has two goals: enforcer:enforce and enforcer:display-info. The enforce goal runs during a project build to execute rules specified in the configuration, while the display-info goal shows current information about the built-in rules that are present in the project's pom.xml.

What is the enforcer plugin?

The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family along with many more built-in rules and user created rules. The Enforcer plugin has two goals: enforcer:enforce executes rules for each project in a multi-project build.


Video Answer


2 Answers

Alternatively when building the specific module from command line you can use the following command option.

mvn -Denforcer.skip=true clean install
mvn -Denforcer.skip=true clean package
like image 86
mtotowamkwe Avatar answered Oct 27 '22 18:10

mtotowamkwe


In the POM of the module, set enforcer.skip to true:

<properties>
  <enforcer.skip>true</enforcer.skip>
</properties>
like image 44
J Fabian Meier Avatar answered Oct 27 '22 18:10

J Fabian Meier