AAE-49637 Configure Mockito as a build agent to stop runtime self-attach - #2528
Conversation
Pre-attach mockito-core via Surefire/Failsafe argLine so ByteBuddy is loaded at JVM startup instead of self-attaching at runtime. Co-authored-by: Cursor <cursoragent@cursor.com>
🔒 Supply Chain SecurityThis PR modifies dependencies. To run a security analysis, comment: The analysis will check for vulnerabilities, typosquatting, maintainer takeovers, and other supply chain risks. |
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent Mockito/ByteBuddy “runtime self-attach” behavior during test execution by pre-attaching a Java agent via Maven test plugin configuration.
Changes:
- Adds
-javaagent:"${org.mockito:mockito-core:jar}"to Surefire and FailsafeargLine. - Introduces
maven-dependency-pluginwith thepropertiesgoal to expose a dependency-jar path as a Maven property for use inargLine.
Suppressed comments (2)
pom.xml:527
maven-dependency-pluginexecution isn’t bound to any lifecycle phase, sodependency:propertieswill not run during a normal build. That means the${org.mockito:mockito-core:jar}property used by surefire/failsafe will typically remain unresolved and the JVM will fail to start with an invalid-javaagentpath.
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
pom.xml:548
- The new
-javaagent:"${org.mockito:mockito-core:jar}"assumes every module running unit tests resolvesorg.mockito:mockito-core. That’s not true for all modules (e.g.activiti-cloud-service-common/activiti-cloud-service-common-confighas JUnit tests but nomockito-coredependency), so${org.mockito:mockito-core:jar}will be undefined and surefire will pass an invalid agent path, breaking test execution. Consider ensuring the agent artifact is always resolved for all test modules (e.g., add a shared test dependency onmockito-core/mockito-agentin a common parent/BOM), or change the build to resolve/copy the agent jar explicitly and reference that path inargLine.
<configuration>
<argLine>@{argLine} -Xmx1024m -javaagent:"${org.mockito:mockito-core:jar}"</argLine>
a7f1c21 to
a026d14
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
pom.xml:523
- The newly added maven-dependency-plugin configuration is not managed in
<pluginManagement>and has no explicit version, while this POM otherwise centralizes plugin versions via properties +<pluginManagement>. This can make builds less reproducible across different Maven installations; consider adding a managed plugin entry (with a pinned version) and keeping the<plugins>section versionless, consistent with the existing pattern.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
pom.xml:528
- The new maven-dependency-plugin execution is not bound to an explicit lifecycle phase. That makes the availability of properties like
org.mockito:mockito-core:jardepend on the goal’s defaultPhase (and therefore on the plugin version), which is fragile for ensuring-javaagentis always resolved before Surefire/Failsafe runs.
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
44e08eb to
e2969fe
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (3)
pom.xml:525
maven-dependency-plugin:propertiesis configured to run duringinitializefor every module, which can add noticeable overhead and property noise because it resolves/exports properties for all project dependencies. Since this is only needed to obtain themockito-coreJAR path for the-javaagentarg, consider scoping the execution (e.g., restrict toorg.mockito:mockito-coreand the needed scopes) or moving the execution into only the modules that setmockito.agent.arg.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
activiti-cloud-service-common/activiti-cloud-services-test-security/pom.xml:16
- The
-javaagentargument wraps the resolved JAR path in quotes. Since Maven/Surefire argument parsing differs across platforms and versions, keeping the arg unquoted is typically safer unless you have a confirmed need to handle spaces in the local repository path.
<properties>
<enforcer.skip>true</enforcer.skip>
<mockito.agent.arg>-javaagent:"${org.mockito:mockito-core:jar}"</mockito.agent.arg>
</properties>
activiti-cloud-service-common/activiti-cloud-services-swagger/pom.xml:14
- The
-javaagentargument wraps the resolved JAR path in quotes. Since Maven/Surefire argument parsing differs across platforms and versions, keeping the arg unquoted is typically safer unless you have a confirmed need to handle spaces in the local repository path.
<artifactId>activiti-cloud-services-swagger</artifactId>
<properties>
<mockito.agent.arg>-javaagent:"${org.mockito:mockito-core:jar}"</mockito.agent.arg>
</properties>
Use empty mockito.agent.arg by default so modules without Mockito on the classpath skip the agent. Modules that already declare mockito-core enable the agent via the existing dependency-plugin properties goal. Co-authored-by: Cursor <cursoragent@cursor.com>
e2969fe to
ef16cfc
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
pom.xml:529
- Binding maven-dependency-plugin's
propertiesgoal to theinitializephase forces dependency resolution even for non-test lifecycles (e.g.,mvn validate), which can slow builds and introduce extra network dependency. Since the resolved property is only used for Surefire/FailsafeargLine, consider running this execution later (e.g.,process-test-classes) so it only happens when tests are part of the build lifecycle.
<phase>initialize</phase>
<goals>
|



What kind of change does this PR introduce?
Description
Does this PR introduce a breaking change? (check one with "x")