You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/07/03 10:55:48 UTC

(maven) branch maven-4.0.x updated: [#11449] Fix Mockito agent: use late binding @{} interpolation and extend to failsafe plugin (#12369) (#12415)

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

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


The following commit(s) were added to refs/heads/maven-4.0.x by this push:
     new 3c97cf0370 [#11449] Fix Mockito agent: use late binding @{} interpolation and extend to failsafe plugin (#12369) (#12415)
3c97cf0370 is described below

commit 3c97cf0370a0ade27adc86f142dc0e952c30e1be
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Jul 3 12:55:42 2026 +0200

    [#11449] Fix Mockito agent: use late binding @{} interpolation and extend to failsafe plugin (#12369) (#12415)
    
    * [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.
    
    Co-authored-by: B V HITESH SAI <hi...@saividya.ac.in>
---
 pom.xml | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/pom.xml b/pom.xml
index 05b15327e1..1ec56e9d1c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -173,6 +173,8 @@ under the License.
     <woodstoxVersion>7.2.1</woodstoxVersion>
     <xmlunitVersion>2.12.0</xmlunitVersion>
     <jacocoArgLine />
+    <argLine.xmx>-Xmx256m</argLine.xmx>
+    <argLine.mockito />
 
     <version.spotless-maven-plugin>3.0.0</version.spotless-maven-plugin>
     <version.palantirJavaFormat>2.80.0</version.palantirJavaFormat>
@@ -734,7 +736,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>
@@ -745,7 +747,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>
@@ -982,19 +984,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>
@@ -1269,13 +1261,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>