When you run a plugin from the command line like mvn enforcer:enforce, it won't use the configuration inside the executions, but your config should run fine if you launch a lifecycle phase like mvn validate. If you want it to run from the CLI directly, move the configuration block outside the executions. See the faq of the maven-dependency-plugin for an example, the problem is the same.
2009/5/19 bgik <bruce_ki...@hotmail.com> > > Brian > I've just tried to build and run your example from > http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html. > There's no problem building it, just my attempt to use it doesnt work. I'm > using mvn 2.0.9. > > I consistently get the error below, any ideas? > > [ERROR] BUILD ERROR > [INFO] > ------------------------------------------------------------------------ > [INFO] One or more required plugin parameters are invalid/missing for > 'enforcer:enforce' > > [0] Inside the definition for plugin 'maven-enforcer-plugin' specify the > following: > > <configuration> > ... > <rules>VALUE</rules> > </configuration>. > > [INFO] > ------------------------------------------------------------------------ > [INFO] Trace > org.apache.maven.lifecycle.LifecycleExecutionException: Error configuring: > org.apache.maven.plugins:maven-enforcer-plugin. Reason: Invalid o > r missing parameters: [Mojo parameter [name: 'rules'; alias: 'null']] for > mojo: org.apache.maven.plugins:maven-enforcer-plugin:1.0-beta-1:en > force > at > > org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:587) > at > > org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512) > at > > org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482) > at > > org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330) > at > > org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291) > at > > org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142) > at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336) > at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129) > at org.apache.maven.cli.MavenCli.main(MavenCli.java:287) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:597) > at > org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) > at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) > at > org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) > at org.codehaus.classworlds.Launcher.main(Launcher.java:375) > Caused by: org.apache.maven.plugin.PluginParameterException: Error > configuring: org.apache.maven.plugins:maven-enforcer-plugin. Reason: Inva > lid or missing parameters: [Mojo parameter [name: 'rules'; alias: 'null']] > for mojo: org.apache.maven.plugins:maven-enforcer-plugin:1.0-beta > -1:enforce > at > > org.apache.maven.plugin.DefaultPluginManager.checkRequiredParameters(DefaultPluginManager.java:1042) > at > > org.apache.maven.plugin.DefaultPluginManager.getConfiguredMojo(DefaultPluginManager.java:659) > at > > org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:429) > at > > org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558) > ... 16 more > [INFO] > ------------------------------------------------------------------------ > [INFO] Total time: 7 seconds > [INFO] Finished at: Tue May 19 17:21:43 BST 2009 > [INFO] Final Memory: 6M/11M > [INFO] > ------------------------------------------------------------------------ > > My plugin config is:- > > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-enforcer-plugin</artifactId> > <version>1.0-beta-1</version> > <dependencies> > <dependency> > <groupId>custom-rule</groupId> > <artifactId>custom-rule-sample</artifactId> > <version>1.0</version> > </dependency> > </dependencies> > <executions> > <execution> > <id>enforce</id> > <configuration> > <rules> > <myCustomRule > implementation="org.apache.maven.enforcer.rule.MyCustomRule"> > <shouldIfail>false</shouldIfail> > </myCustomRule> > </rules> > </configuration> > <goals> > <goal>enforce</goal> > </goals> > </execution> > </executions> > </plugin> > > thanks > Bruce > > > bgik wrote: > > > > Hi Brian > > Thanks for the swift reply. I'll take a look at this. > > > > much appreciated > > > > > > BRIAN FOX-5 wrote: > >> > >> The maven-enforcer-plugin is well suited for this. You could use one of > >> the > >> existing rules, perhaps the failIfFileExists or easily write your own > >> rule. > >> > >> On Mon, May 18, 2009 at 12:47 PM, bgik <bruce_ki...@hotmail.com> wrote: > >> > >>> > >>> Hi > >>> I have a 3rd party lib that i have no control over. > >>> > >>> In my env it makes no sense to create 2 instances of a given class from > >>> this > >>> lib, in fact it may cause issues, so i have updated my codebase to wrap > >>> one > >>> in a singleton. Going forward there's nothing to stop anyone creating > >>> another one though. > >>> > >>> What i would like is for > >>> > >>> mvn compile > >>> > >>> to actually fail even though my code is syntactically correct if it > >>> encounters any attempt to create a 2nd instance of this class. > >>> > >>> Is there a way to do this? I presume I could write some plugin but i'd > >>> like > >>> to avoid that if possible as time is short > >>> > >>> many thanks > >>> -- > >>> View this message in context: > >>> > http://www.nabble.com/Have-maven-stop-compilation-when-some-rule-is-broken-tp23601222p23601222.html > >>> Sent from the Maven - Users mailing list archive at Nabble.com. > >>> > >>> > >>> --------------------------------------------------------------------- > >>> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > >>> For additional commands, e-mail: users-h...@maven.apache.org > >>> > >>> > >> > >> > > > > > > -- > View this message in context: > http://www.nabble.com/Have-maven-stop-compilation-when-some-rule-is-broken-tp23601222p23619752.html > Sent from the Maven - Users mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache.org > >