Hiteshsai007 opened a new pull request, #13397: URL: https://github.com/apache/maven/pull/13397
Resolves [#374](https://github.com/OpenHands/maven/issues/374) ([MNG-7525](https://issues.apache.org/jira/browse/MNG-7525)) https://github.com/OpenHands/maven/pull/582 Maven warns when a plugin goal is not marked as thread-safe, but parallel reactor builds can still execute multiple instances of that goal at the same time. Plugin authors are currently expected to implement their own global locking and then mark the goal thread-safe, which neither protects existing plugins nor accurately describes their concurrency behavior. This change makes Maven serialize executions of a non-thread-safe mojo by synchronizing on its implementation class. This keeps independent, thread-safe mojos parallel while preventing overlapping executions of the same unsafe implementation. ## How this solves the problem The plugin execution path in `DefaultBuildPluginManager` now explicitly handles mojos whose descriptors are not marked thread-safe: 1. **Resolve the implementation class monitor** Maven obtains the concrete implementation class for both Maven 3 and Maven 4 API mojos. For Maven 4 API mojos it uses the wrapped implementation rather than the common wrapper class, so unrelated Maven 4 mojos do not share a lock. 2. **Serialize unsafe executions** When a mojo descriptor is not marked as thread-safe, Maven invokes its execution listeners and `execute()` method while synchronized on that implementation class. 3. **Preserve parallel execution for safe mojos** Mojos marked thread-safe continue through the existing unsynchronized execution path. ## Why this matters A plugin descriptor's thread-safe flag identifies whether concurrent invocations are safe. By enforcing that boundary in Maven, existing non-thread-safe plugins are protected during parallel reactor builds without requiring each plugin author to add a global lock or make an inaccurate thread-safety claim. ## Testing Added a Core IT that builds two independent reactor modules with `-T2`. Both invoke the same deliberately non-thread-safe mojo, which detects and fails on concurrent execution. The test passes only when Maven serializes those mojo invocations. ## Checklist - [x] Your pull request should address just one issue, without pulling in other changes. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Each commit in the pull request should have a meaningful subject line and body. - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. - [x] Run `mvn verify` to make sure basic checks pass. - [x] You have run the Core IT successfully. To make clear that you license your contribution under the Apache License Version 2.0, January 2004, you have to acknowledge this by using the following checkbox. - [x] I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004 - [ ] In any other case, please file an Apache Individual Contributor License Agreement. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
