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

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


The following commit(s) were added to refs/heads/master by this push:
     new 6f4644329f [#11449] Fix Mockito agent: use late binding @{} 
interpolation and extend to failsafe plugin (#12369)
6f4644329f is described below

commit 6f4644329fd2fb625ea2412239e049ff0446f600
Author: B V HITESH SAI <[email protected]>
AuthorDate: Fri Jul 3 14:44:08 2026 +0530

    [#11449] Fix Mockito agent: use late binding @{} interpolation and extend 
to failsafe plugin (#12369)
    
    * [MNG-11449] Fix Mockito agent: use late binding @{} interpolation and 
extend to failsafe plugin
    
    The mockito profile activated by dependency:properties used Maven property
    interpolation (\) which resolves at POM parse time - before the
    dependency:properties goal runs and sets the org.mockito:mockito-core:jar
    property. This caused the javaagent path to remain unresolved.
    
    Fix: use Surefire/Failsafe late-binding property interpolation (@{...})
    which resolves the property at test execution time, after 
dependency:properties
    has already set it.
    
    Also:
    - Restore @{jacocoArgLine} placeholder (was dropped in previous attempt)
    - Extend the profile to cover maven-failsafe-plugin as well
    
    Fixes: https://issues.apache.org/jira/browse/MNG-11449
    
    * [MNG-11449] Fix Mockito agent profile collision with JaCoCo profile
    
    When both jacoco and mockito profiles were active, the jacoco profile's 
surefire configuration overrode the mockito profile's surefire pluginManagement 
configuration. This caused the mockito javaagent to be silently dropped for 
unit tests.
    
    Fix: Refactor the surefire and failsafe argLine to be composed dynamically 
via properties:
    - Define argLine.xmx (default: -Xmx256m) and argLine.mockito (default: 
empty) in the root POM properties.
    - Update default pluginManagement configuration for surefire/failsafe to: \ 
@{jacocoArgLine} \
    - Modify the mockito profile to only set argLine.mockito property to the 
mockito javaagent.
    - Modify the jacoco profile to only override argLine.xmx property to -Xmx1G 
and remove the direct surefire argLine override.
    
    This ensures both profiles can be active simultaneously without overriding 
each other's configurations.
---
 pom.xml | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/pom.xml b/pom.xml
index d433186b4e..669db091d2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -172,6 +172,8 @@ under the License.
     <woodstoxVersion>7.2.1</woodstoxVersion>
     <xmlunitVersion>2.12.0</xmlunitVersion>
     <jacocoArgLine />
+    <argLine.xmx>-Xmx256m</argLine.xmx>
+    <argLine.mockito />
 
     <!-- Set as system property in surefire/failsafe to propagate to tests and 
IT Verifier -->
     <toolboxVersion>0.14.1</toolboxVersion>
@@ -702,7 +704,7 @@ under the License.
           <artifactId>maven-surefire-plugin</artifactId>
           <configuration>
             <forkNode 
implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"
 />
-            <argLine>-Xmx256m @{jacocoArgLine}</argLine>
+            <argLine>${argLine.xmx} @{jacocoArgLine} 
${argLine.mockito}</argLine>
             <systemPropertyVariables combine.children="append">
               <version.toolbox>${toolboxVersion}</version.toolbox>
             </systemPropertyVariables>
@@ -713,7 +715,7 @@ under the License.
           <artifactId>maven-failsafe-plugin</artifactId>
           <configuration>
             <forkNode 
implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"
 />
-            <argLine>-Xmx256m @{jacocoArgLine}</argLine>
+            <argLine>${argLine.xmx} @{jacocoArgLine} 
${argLine.mockito}</argLine>
             <systemPropertyVariables combine.children="append">
               <version.toolbox>${toolboxVersion}</version.toolbox>
             </systemPropertyVariables>
@@ -950,19 +952,9 @@ under the License.
           <name>org.mockito:mockito-core:jar</name>
         </property>
       </activation>
-      <build>
-        <pluginManagement>
-          <plugins>
-            <plugin>
-              <groupId>org.apache.maven.plugins</groupId>
-              <artifactId>maven-surefire-plugin</artifactId>
-              <configuration>
-                <argLine>-Xmx256m 
-javaagent:${org.mockito:mockito-core:jar}</argLine>
-              </configuration>
-            </plugin>
-          </plugins>
-        </pluginManagement>
-      </build>
+      <properties>
+        
<argLine.mockito>-javaagent:@{org.mockito:mockito-core:jar}</argLine.mockito>
+      </properties>
     </profile>
     <profile>
       <id>graph</id>
@@ -1216,13 +1208,15 @@ under the License.
     </profile>
     <profile>
       <id>jacoco</id>
+      <properties>
+        <argLine.xmx>-Xmx1G</argLine.xmx>
+      </properties>
       <build>
         <plugins>
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <configuration>
-              <argLine>-Xmx1G @{jacocoArgLine}</argLine>
               
<reportsDirectory>${project.build.directory}/test-results-surefire</reportsDirectory>
             </configuration>
           </plugin>

Reply via email to