Summary
ToolchainMojo uses a static LOCK object for synchronized around toolchainManagerPrivate.storeToolchainToBuildContext(). The storeToolchainToBuildContext method already operates on a per-session build context, making the static synchronization unnecessary and potentially causing contention in multi-module builds.
Location
ToolchainMojo.java:29, 67-69
https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java#L29
https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java#L67-L69
Code
private static final Object LOCK = new Object();
// ...
synchronized (LOCK) {
toolchainManagerPrivate.storeToolchainToBuildContext(tc, session);
}
Problem
- The plugin is marked
threadSafe = true, meaning Maven may execute it concurrently for different modules/sessions
storeToolchainToBuildContext() stores data into the build context, which is already per-session and thread-safe
- The static lock introduces unnecessary contention: one module's toolchain selection blocks another unrelated module's selection
- This defeats the purpose of
threadSafe = true
Impact
In multi-module Maven builds where the toolchains plugin runs in multiple modules (e.g., via inherited plugin configuration), the static lock serializes what could otherwise run in parallel, slowing down builds.
Suggested Fix
Remove the synchronized block entirely, as storeToolchainToBuildContext already handles its own concurrency per session.
Summary
ToolchainMojouses a staticLOCKobject forsynchronizedaroundtoolchainManagerPrivate.storeToolchainToBuildContext(). ThestoreToolchainToBuildContextmethod already operates on a per-session build context, making the static synchronization unnecessary and potentially causing contention in multi-module builds.Location
ToolchainMojo.java:29, 67-69https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java#L29
https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java#L67-L69
Code
Problem
threadSafe = true, meaning Maven may execute it concurrently for different modules/sessionsstoreToolchainToBuildContext()stores data into the build context, which is already per-session and thread-safethreadSafe = trueImpact
In multi-module Maven builds where the toolchains plugin runs in multiple modules (e.g., via inherited plugin configuration), the static lock serializes what could otherwise run in parallel, slowing down builds.
Suggested Fix
Remove the
synchronizedblock entirely, asstoreToolchainToBuildContextalready handles its own concurrency per session.