From 62bd88847eea7090a38ea2f6718b41eb77d157b1 Mon Sep 17 00:00:00 2001 From: B V HITESH SAI Date: Fri, 3 Jul 2026 14:44:08 +0530 Subject: [PATCH] [#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 05b15327e1a3..1ec56e9d1c45 100644 --- a/pom.xml +++ b/pom.xml @@ -173,6 +173,8 @@ under the License. 7.2.1 2.12.0 + -Xmx256m + 3.0.0 2.80.0 @@ -734,7 +736,7 @@ under the License. maven-surefire-plugin - -Xmx256m @{jacocoArgLine} + ${argLine.xmx} @{jacocoArgLine} ${argLine.mockito} ${toolboxVersion} @@ -745,7 +747,7 @@ under the License. maven-failsafe-plugin - -Xmx256m @{jacocoArgLine} + ${argLine.xmx} @{jacocoArgLine} ${argLine.mockito} ${toolboxVersion} @@ -982,19 +984,9 @@ under the License. org.mockito:mockito-core:jar - - - - - org.apache.maven.plugins - maven-surefire-plugin - - -Xmx256m -javaagent:${org.mockito:mockito-core:jar} - - - - - + + -javaagent:@{org.mockito:mockito-core:jar} + graph @@ -1269,13 +1261,15 @@ under the License. jacoco + + -Xmx1G + org.apache.maven.plugins maven-surefire-plugin - -Xmx1G @{jacocoArgLine} ${project.build.directory}/test-results-surefire