This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git


The following commit(s) were added to refs/heads/master by this push:
     new c7d12e76 Add the evaluateGroovy rule
c7d12e76 is described below

commit c7d12e765d44eb0e28d8fe3fc5b6d88686729d27
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Sep 20 15:44:58 2026 +0200

    Add the evaluateGroovy rule
    
    Groovy is the replacement engine for BeanShell across Maven
    (apache/maven#13207). The dependency is optional: Groovy is ~7 MB and
    the enforcer runs in nearly every build, so users who want the rule add
    org.apache.groovy:groovy to the plugin declaration and the rule reports
    its absence in one line.
---
 enforcer-rules/pom.xml                             |   7 ++
 .../maven/enforcer/rules/EvaluateBeanshell.java    |   7 +-
 ...{EvaluateBeanshell.java => EvaluateGroovy.java} |  80 ++++++++-------
 .../src/site/markdown/evaluateBeanshell.md.vm      |   2 +-
 ...valuateBeanshell.md.vm => evaluateGroovy.md.vm} |  45 +++++----
 enforcer-rules/src/site/markdown/index.md          |   3 +-
 .../maven/enforcer/rules/TestEvaluateGroovy.java   | 110 +++++++++++++++++++++
 .../evaluate-groovy-missing/invoker.properties     |  19 ++++
 .../it/projects/evaluate-groovy-missing/pom.xml    |  54 ++++++++++
 .../projects/evaluate-groovy-missing/verify.groovy |  21 ++++
 .../src/it/projects/evaluate-groovy/pom.xml        |  65 ++++++++++++
 .../src/it/projects/evaluate-groovy/verify.groovy  |  22 +++++
 pom.xml                                            |   2 +
 13 files changed, 375 insertions(+), 62 deletions(-)

diff --git a/enforcer-rules/pom.xml b/enforcer-rules/pom.xml
index 28add428..031370aa 100644
--- a/enforcer-rules/pom.xml
+++ b/enforcer-rules/pom.xml
@@ -117,6 +117,13 @@
       <artifactId>bsh</artifactId>
       <version>2.0b6</version>
     </dependency>
+    <dependency>
+      <!-- for evaluateGroovy; not shipped with the plugin, users add it to 
the plugin declaration -->
+      <groupId>org.apache.groovy</groupId>
+      <artifactId>groovy</artifactId>
+      <version>${version.groovy}</version>
+      <optional>true</optional>
+    </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-params</artifactId>
diff --git 
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateBeanshell.java
 
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateBeanshell.java
index b6c14008..8af8a293 100644
--- 
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateBeanshell.java
+++ 
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateBeanshell.java
@@ -33,8 +33,9 @@ import 
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator
  * Rule for Maven Enforcer using Beanshell to evaluate a conditional 
expression.
  *
  * @author hugonnem
- * @deprecated BeanShell is being retired across Maven; the rule will be 
removed in a future major version. Express
- *             the condition with one of the built-in rules such as {@code 
requireProperty}, or write a custom rule.
+ * @deprecated BeanShell is being retired across Maven; the rule will be 
removed in a future major version. Use
+ *             {@link EvaluateGroovy} ({@code evaluateGroovy}) or one of the 
built-in rules such as
+ *             {@code requireProperty}.
  */
 @Deprecated
 @Named("evaluateBeanshell")
@@ -65,7 +66,7 @@ public final class EvaluateBeanshell extends 
AbstractStandardEnforcerRule {
     @Override
     public void execute() throws EnforcerRuleException {
         getLog().warn("The evaluateBeanshell rule is deprecated and will be 
removed in a future major version;"
-                + " express the condition with a built-in rule such as 
requireProperty, or write a custom rule.");
+                + " use evaluateGroovy or a built-in rule such as 
requireProperty instead.");
 
         try {
             getLog().debug("Echo condition : " + condition);
diff --git 
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateBeanshell.java
 
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateGroovy.java
similarity index 51%
copy from 
enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateBeanshell.java
copy to 
enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateGroovy.java
index b6c14008..b9f5d5e2 100644
--- 
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateBeanshell.java
+++ 
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/EvaluateGroovy.java
@@ -23,34 +23,30 @@ import javax.inject.Named;
 
 import java.util.Objects;
 
-import bsh.EvalError;
-import bsh.Interpreter;
+import groovy.lang.GroovyShell;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleError;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import 
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
 import 
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
 
 /**
- * Rule for Maven Enforcer using Beanshell to evaluate a conditional 
expression.
+ * Rule for Maven Enforcer using Groovy to evaluate a conditional expression.
+ * <p>
+ * Groovy is not shipped with the plugin: add {@code org.apache.groovy:groovy} 
as a dependency of the
+ * {@code maven-enforcer-plugin} declaration to use this rule.
  *
- * @author hugonnem
- * @deprecated BeanShell is being retired across Maven; the rule will be 
removed in a future major version. Express
- *             the condition with one of the built-in rules such as {@code 
requireProperty}, or write a custom rule.
+ * @since 3.8.0
  */
-@Deprecated
-@Named("evaluateBeanshell")
-public final class EvaluateBeanshell extends AbstractStandardEnforcerRule {
+@Named("evaluateGroovy")
+public final class EvaluateGroovy extends AbstractStandardEnforcerRule {
 
-    /** Beanshell interpreter. */
-    private final Interpreter interpreter = new Interpreter();
-
-    /** The condition to be evaluated.
-     * */
+    /** The condition to be evaluated. */
     private String condition;
 
     private final ExpressionEvaluator evaluator;
 
     @Inject
-    public EvaluateBeanshell(ExpressionEvaluator evaluator) {
+    public EvaluateGroovy(ExpressionEvaluator evaluator) {
         this.evaluator = Objects.requireNonNull(evaluator);
     }
 
@@ -64,15 +60,22 @@ public final class EvaluateBeanshell extends 
AbstractStandardEnforcerRule {
 
     @Override
     public void execute() throws EnforcerRuleException {
-        getLog().warn("The evaluateBeanshell rule is deprecated and will be 
removed in a future major version;"
-                + " express the condition with a built-in rule such as 
requireProperty, or write a custom rule.");
+        if (condition == null || condition.trim().isEmpty()) {
+            throw new EnforcerRuleError("The evaluateGroovy rule requires a 
condition");
+        }
+        try {
+            Class.forName("groovy.lang.GroovyShell", false, 
getClass().getClassLoader());
+        } catch (ClassNotFoundException e) {
+            throw new EnforcerRuleError("The evaluateGroovy rule needs Groovy 
on the plugin classpath: add"
+                    + " org.apache.groovy:groovy as a dependency of the 
maven-enforcer-plugin declaration");
+        }
 
         try {
             getLog().debug("Echo condition : " + condition);
-            // Evaluate condition within Plexus Container
+            // interpolate ${...} against the project before handing the 
script to Groovy
             String script = (String) evaluator.evaluate(condition);
             getLog().debug("Echo script : " + script);
-            if (!evaluateCondition(script)) {
+            if (!GroovyEvaluation.evaluate(script)) {
                 String message = getMessage();
                 if (message == null || message.isEmpty()) {
                     message = "The expression \"" + condition + "\" is not 
true.";
@@ -84,26 +87,29 @@ public final class EvaluateBeanshell extends 
AbstractStandardEnforcerRule {
         }
     }
 
+    @Override
+    public String toString() {
+        return String.format("EvaluateGroovy[message=%s, condition=%s]", 
getMessage(), condition);
+    }
+
     /**
-     * Evaluate expression using Beanshell.
-     *
-     * @param script the expression to be evaluated
-     * @return boolean the evaluation of the expression
-     * @throws EnforcerRuleException if the script could not be evaluated
+     * Kept apart so that the rule class itself loads without Groovy on the 
classpath and can report that.
      */
-    private boolean evaluateCondition(String script) throws 
EnforcerRuleException {
-        Boolean evaluation;
-        try {
-            evaluation = (Boolean) interpreter.eval(script);
-            getLog().debug("Echo evaluating : " + evaluation);
-        } catch (EvalError ex) {
-            throw new EnforcerRuleException("Couldn't evaluate condition: " + 
script, ex);
-        }
-        return evaluation;
-    }
+    private static final class GroovyEvaluation {
+        private GroovyEvaluation() {}
 
-    @Override
-    public String toString() {
-        return String.format("EvaluateBeanshell[message=%s, condition=%s]", 
getMessage(), condition);
+        static boolean evaluate(String script) throws EnforcerRuleException {
+            Object result;
+            try {
+                result = new GroovyShell().evaluate(script);
+            } catch (RuntimeException | LinkageError ex) {
+                throw new EnforcerRuleException("Couldn't evaluate condition: 
" + script, ex);
+            }
+            if (!(result instanceof Boolean)) {
+                throw new EnforcerRuleException("The condition must evaluate 
to a boolean but gave " + result + " ("
+                        + (result == null ? "null" : 
result.getClass().getName()) + "): " + script);
+            }
+            return (Boolean) result;
+        }
     }
 }
diff --git a/enforcer-rules/src/site/markdown/evaluateBeanshell.md.vm 
b/enforcer-rules/src/site/markdown/evaluateBeanshell.md.vm
index 0687e7a7..5498a051 100644
--- a/enforcer-rules/src/site/markdown/evaluateBeanshell.md.vm
+++ b/enforcer-rules/src/site/markdown/evaluateBeanshell.md.vm
@@ -26,7 +26,7 @@ under the License.
 
 # Beanshell
 
-**Deprecated.** BeanShell is being retired across Maven 
([apache/maven#13207](https://github.com/apache/maven/issues/13207)) and this 
rule will be removed in a future major version. Express the condition with a 
built-in rule such as [requireProperty](./requireProperty.html), 
[requireFilesExist](./requireFilesExist.html) or [requireOS](./requireOS.html), 
or [write a custom 
rule](https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html).
+**Deprecated.** BeanShell is being retired across Maven 
([apache/maven#13207](https://github.com/apache/maven/issues/13207)) and this 
rule will be removed in a future major version. Use 
[evaluateGroovy](./evaluateGroovy.html) instead, or a built-in rule such as 
[requireProperty](./requireProperty.html), 
[requireFilesExist](./requireFilesExist.html) or [requireOS](./requireOS.html).
 
 This rule can execute a beanshell script and evaluate the result.
 
diff --git a/enforcer-rules/src/site/markdown/evaluateBeanshell.md.vm 
b/enforcer-rules/src/site/markdown/evaluateGroovy.md.vm
similarity index 50%
copy from enforcer-rules/src/site/markdown/evaluateBeanshell.md.vm
copy to enforcer-rules/src/site/markdown/evaluateGroovy.md.vm
index 0687e7a7..8f3cbbee 100644
--- a/enforcer-rules/src/site/markdown/evaluateBeanshell.md.vm
+++ b/enforcer-rules/src/site/markdown/evaluateGroovy.md.vm
@@ -1,8 +1,5 @@
 ---
-title: Beanshell
-author: 
-  - Brian Fox
-date: 2007-09-01
+title: Groovy
 ---
 
 <!--
@@ -23,16 +20,18 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 -->
+# Groovy
 
-# Beanshell
+This rule evaluates a [Groovy](https://groovy-lang.org/) expression and fails 
unless the result is `true`.
+Maven properties in the condition (`${...}`) are interpolated before Groovy 
sees it, so quote them where a
+string is meant. It replaces the deprecated 
[evaluateBeanshell](./evaluateBeanshell.html) rule.
 
-**Deprecated.** BeanShell is being retired across Maven 
([apache/maven#13207](https://github.com/apache/maven/issues/13207)) and this 
rule will be removed in a future major version. Express the condition with a 
built-in rule such as [requireProperty](./requireProperty.html), 
[requireFilesExist](./requireFilesExist.html) or [requireOS](./requireOS.html), 
or [write a custom 
rule](https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html).
-
-This rule can execute a beanshell script and evaluate the result.
+Groovy is not shipped with the plugin: add `org.apache.groovy:groovy` as a 
dependency of the plugin
+declaration, as in the sample below. Without it the rule fails with a message 
saying so.
 
 The following parameters are supported by this rule:
 
-- **condition** - the beanshell statement to evaluate.
+- **condition** - the Groovy expression to evaluate; it must yield a boolean.
 - **message** - an optional message to the user if the rule fails.
 
 Sample Plugin Configuration:
@@ -46,17 +45,28 @@ Sample Plugin Configuration:
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-enforcer-plugin</artifactId>
         <version>${project.version}</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.groovy</groupId>
+            <artifactId>groovy</artifactId>
+            <version>4.0.33</version>
+          </dependency>
+        </dependencies>
         <executions>
           <execution>
-            <id>enforce-beanshell</id>
+            <id>enforce-groovy</id>
             <goals>
               <goal>enforce</goal>
             </goals>
             <configuration>
               <rules>
-                <evaluateBeanshell>
-                  <condition>\${project.artifactId} == foo</condition>
-                </evaluateBeanshell>
+                <evaluateGroovy>
+                  <condition>'\${project.artifactId}' == 'foo'</condition>
+                </evaluateGroovy>
+                <evaluateGroovy>
+                  <condition>'\${project.version}'.endsWith('-SNAPSHOT') || 
System.getenv('RELEASE') != null</condition>
+                  <message>Release builds must set RELEASE</message>
+                </evaluateGroovy>
               </rules>
               <fail>true</fail>
             </configuration>
@@ -69,10 +79,5 @@ Sample Plugin Configuration:
 </project>
 ```
 
-The condition can be a complex script or a simple expression. As long as it 
results in True, the rule will succeed. This means code can be executed as long 
as the last line results in true.
-
-```xml
-  <evaluateBeanshell>
-    <condition>for (int i = 0;i!=10;i++){print ("Hello World 
"+i);};1==1</condition>
-  </evaluateBeanshell>
-```
+Porting a BeanShell condition: BeanShell compared bare words, so 
`\${project.artifactId} == foo` worked once
+interpolated to `foo == foo`; Groovy needs both sides quoted, 
`'\${project.artifactId}' == 'foo'`.
diff --git a/enforcer-rules/src/site/markdown/index.md 
b/enforcer-rules/src/site/markdown/index.md
index 9cc9f841..5942fbab 100644
--- a/enforcer-rules/src/site/markdown/index.md
+++ b/enforcer-rules/src/site/markdown/index.md
@@ -41,7 +41,8 @@ The following built-in rules ship along with the enforcer 
plugin:
 - [banTransitiveDependencies](./banTransitiveDependencies.html) - enforces 
that project doesn't have transitive dependencies.
 - [dependencyConvergence](./dependencyConvergence.html) - ensure all 
dependencies converge to the same version.
 - [enforceBytecodeVersion](./enforceBytecodeVersion.html) - enforces that 
dependency bytecode versions do not exceed the configured maximum.
-- [evaluateBeanshell](./evaluateBeanshell.html) - evaluates a beanshell script 
(deprecated).
+- [evaluateBeanshell](./evaluateBeanshell.html) - evaluates a beanshell script 
(deprecated, use evaluateGroovy).
+- [evaluateGroovy](./evaluateGroovy.html) - evaluates a Groovy expression.
 - [externalRules](./externalRules.html) - evaluate rules from an external 
resource.
 - [reactorModuleConvergence](./reactorModuleConvergence.html) - enforces that 
a multi module build follows best practice.
 - [requireActiveProfile](./requireActiveProfile.html) - enforces one or more 
active profiles.
diff --git 
a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestEvaluateGroovy.java
 
b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestEvaluateGroovy.java
new file mode 100644
index 00000000..addcc6ac
--- /dev/null
+++ 
b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestEvaluateGroovy.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.enforcer.rules;
+
+import org.apache.maven.enforcer.rule.api.EnforcerLogger;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleError;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rules.utils.ExpressionEvaluator;
+import 
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class TestEvaluateGroovy {
+
+    @Mock
+    private ExpressionEvaluator evaluator;
+
+    @InjectMocks
+    private EvaluateGroovy rule;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        rule.setLog(Mockito.mock(EnforcerLogger.class));
+        // we need not testing ExpressionEvaluator
+        lenient().when(evaluator.evaluate(anyString())).thenAnswer(i -> 
i.getArgument(0));
+    }
+
+    @Test
+    void conditionThatHoldsPasses() throws Exception {
+        rule.setCondition("'This is a test.' == 'This is a test.'");
+        rule.execute();
+    }
+
+    @Test
+    void groovyIdiomsAreAvailable() throws Exception {
+        rule.setCondition("'1.0-SNAPSHOT'.endsWith('-SNAPSHOT') && [1, 2, 
3].every { it > 0 }");
+        rule.execute();
+    }
+
+    @Test
+    void conditionThatFailsUsesTheMessage() {
+        rule.setCondition("'Test' == null");
+        rule.setMessage("We have a variable : ${env}");
+        EnforcerRuleException e = assertThrows(EnforcerRuleException.class, () 
-> rule.execute());
+        assertEquals(rule.getMessage(), e.getMessage());
+    }
+
+    @Test
+    void conditionThatFailsWithoutMessage() {
+        rule.setCondition("'Test' == null");
+        EnforcerRuleException e = assertThrows(EnforcerRuleException.class, () 
-> rule.execute());
+        assertEquals("The expression \"'Test' == null\" is not true.", 
e.getMessage());
+    }
+
+    @Test
+    void conditionThatIsNotBooleanIsRejected() {
+        rule.setCondition("'a string'");
+        EnforcerRuleException e = assertThrows(EnforcerRuleException.class, () 
-> rule.execute());
+        assertTrue(e.getMessage().contains("must evaluate to a boolean"), 
e.getMessage());
+    }
+
+    @Test
+    void conditionThatDoesNotCompileIsReported() {
+        rule.setCondition("this is not groovy ((");
+        EnforcerRuleException e = assertThrows(EnforcerRuleException.class, () 
-> rule.execute());
+        assertTrue(e.getMessage().startsWith("Couldn't evaluate condition"), 
e.getMessage());
+    }
+
+    @Test
+    void missingConditionIsAnError() {
+        assertThrows(EnforcerRuleError.class, () -> rule.execute());
+    }
+
+    @Test
+    void unresolvableExpressionIsReported() throws Exception {
+        rule.setCondition("${env} == null");
+        when(evaluator.evaluate(rule.getCondition())).thenThrow(new 
ExpressionEvaluationException("expected error"));
+        EnforcerRuleException e = assertThrows(EnforcerRuleException.class, () 
-> rule.execute());
+        assertEquals("Unable to evaluate an expression '${env} == null'", 
e.getMessage());
+    }
+}
diff --git 
a/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/invoker.properties
 
b/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/invoker.properties
new file mode 100644
index 00000000..ccc78b66
--- /dev/null
+++ 
b/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/invoker.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+invoker.buildResult = failure
diff --git 
a/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/pom.xml 
b/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/pom.xml
new file mode 100644
index 00000000..812a9961
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.enforcer</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <description>
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>test</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <evaluateGroovy>
+                  <condition>true</condition>
+                </evaluateGroovy>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/verify.groovy 
b/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/verify.groovy
new file mode 100644
index 00000000..95348244
--- /dev/null
+++ 
b/maven-enforcer-plugin/src/it/projects/evaluate-groovy-missing/verify.groovy
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+File buildLog = new File(basedir, 'build.log')
+assert buildLog.text.contains('The evaluateGroovy rule needs Groovy on the 
plugin classpath')
diff --git a/maven-enforcer-plugin/src/it/projects/evaluate-groovy/pom.xml 
b/maven-enforcer-plugin/src/it/projects/evaluate-groovy/pom.xml
new file mode 100644
index 00000000..18bc8075
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/evaluate-groovy/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.enforcer</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <description>
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.groovy</groupId>
+            <artifactId>groovy</artifactId>
+            <version>@version.groovy@</version>
+          </dependency>
+        </dependencies>
+        <executions>
+          <execution>
+            <id>test</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <evaluateGroovy>
+                  <condition>'${project.artifactId}' == 'test'</condition>
+                </evaluateGroovy>
+                <evaluateGroovy>
+                  <condition>'${project.version}'.tokenize('.').size() == 
2</condition>
+                  <message>The version must have two components</message>
+                </evaluateGroovy>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/maven-enforcer-plugin/src/it/projects/evaluate-groovy/verify.groovy 
b/maven-enforcer-plugin/src/it/projects/evaluate-groovy/verify.groovy
new file mode 100644
index 00000000..131d89c6
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/evaluate-groovy/verify.groovy
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+File buildLog = new File(basedir, 'build.log')
+assert buildLog.text.contains('[INFO] Rule 0: 
org.apache.maven.enforcer.rules.EvaluateGroovy passed')
+assert buildLog.text.contains('[INFO] Rule 1: 
org.apache.maven.enforcer.rules.EvaluateGroovy passed')
diff --git a/pom.xml b/pom.xml
index 2fee309c..43cb983b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,6 +84,8 @@
     <!-- the same as in Maven  -->
     <resolver.version>1.9.27</resolver.version>
     <version.slf4j>1.7.36</version.slf4j>
+    <!-- optional dependency of the evaluateGroovy rule; ITs add it to the 
plugin -->
+    <version.groovy>4.0.33</version.groovy>
 
     <!-- plugins used in IT, not defined in parent -->
     <version.maven-pmd-plugin>3.28.0</version.maven-pmd-plugin>

Reply via email to