Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use of the Maven Enforcer plugin?

Tags:

I'd like to use the Maven Enforcer plugin to check to see if I have duplicate classes on my path.

I've tried the example from here.

But when I run it like this:

mvn enforcer:enforce

I get this error:

Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.0.1:enforce (default-cli) on project datapopulator: The parameters 'rules' for goal org.apache.maven.plugins:maven-enforcer-plugin:1.0.1:enforce are missing or invalid

Is there a way to use this correctly?

EDIT #1

If changing my config to this:

        <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-enforcer-plugin</artifactId>             <version>1.0.1</version>             <executions>                 <execution>                     <id>enforce-versions</id>                     <goals>                         <goal>enforce</goal>                     </goals>                     <configuration>                         <rules>                             <AlwaysPass />                         </rules>                         <fail>true</fail>                     </configuration>                 </execution>             </executions>         </plugin> 

Produces the same error.

like image 690
javamonkey79 Avatar asked Jul 19 '11 22:07

javamonkey79


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 dependencies 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.

Which plugin goal can be used to cause a build failure if the project uses an old version of Maven or Java?

<artifactId>maven-enforcer-plugin</artifactId> <version>3.1. 0</version>


2 Answers

The reason why your first version did not work is because there is a difference between a plug-in configuration inside the execution tag and a plug-in configuration outside the execution tag. The execution is only used when your plug-in is triggered by a special phase of the complete Maven build.

The Maven guide to configuration explains it better:

Configurations inside the tag differ from those that are outside in that they cannot be used from a direct command line invocation. Instead they are only applied when the lifecycle phase they are bound to are invoked. Alternatively, if you move a configuration section outside of the executions section, it will apply globally to all invocations of the plugin.

like image 146
Thomas Avatar answered Nov 28 '22 10:11

Thomas


Try this, moving the configuration outside executions, so it isn't bound to the life cycle phase.

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-enforcer-plugin</artifactId>     <version>1.0.1</version>     <executions>         <execution>             <id>enforce-versions</id>             <goals>                 <goal>enforce</goal>             </goals>         </execution>     </executions>     <configuration>         <rules>             <AlwaysPass />         </rules>         <fail>true</fail>     </configuration> </plugin> 

Now when you do mvn enforcer:enforce, it picks the rules from your pom.xml.

like image 36
Raj Shenoy Avatar answered Nov 28 '22 10:11

Raj Shenoy