gnodet opened a new issue, #13839:
URL: https://github.com/apache/maven/issues/13839
## Summary
`org.apache.maven.api.di.MojoExecutionScoped` (in `maven-api-di`) is an
unfinished, unusable annotation that should be deprecated on the `maven-4.0.x`
branch and removed in a future major version.
## Why it is unusable
1. **Guice binding is commented out.**
`MojoExecutionScopeModule.configure()` has the v4 annotation binding explicitly
commented out:
```java
// bindScope(org.apache.maven.api.di.MojoExecutionScoped.class, scope);
```
Only the v3 annotation
(`org.apache.maven.execution.scope.MojoExecutionScoped`) is registered in
Guice/Sisu.
2. **No proxy path in maven-di.** Unlike `@SessionScoped` — which creates a
JDK proxy when injected into a wider scope (`SessionScope.createProxy()`) —
`MojoExecutionScope` throws `DIException` if the `ThreadLocal` stack is empty.
Injecting a `@MojoExecutionScoped` component into a `@Singleton` fails at
startup.
3. **No production usage.** No class in Maven itself is annotated with
`org.apache.maven.api.di.MojoExecutionScoped`. All existing usages in ITs and
extensions use the v3 annotation.
4. **v4 plugins don't need it.** For v4 plugins, `DefaultMavenPluginManager`
creates a fresh `Injector` per mojo execution and binds `Session`, `Project`,
`MojoExecution`, and `Log` directly via `bindInstance`. Plain `@Inject` works;
no scope annotation is needed.
## Proposed action for `maven-4.0.x`
Add `@Deprecated` to `org.apache.maven.api.di.MojoExecutionScoped` with a
Javadoc note explaining:
- Why it exists (historical analog to the v3 annotation)
- Why it should not be used (unfinished, no proxy, `ThreadLocal`-based)
- What to use instead (`@SessionScoped` for session-scoped components;
direct `@Inject` for execution context in v4 mojos; v3 `@MojoExecutionScoped`
for legacy extension components in the shared Plexus/Sisu container)
## Longer term
Remove the annotation entirely from `maven-api-di` in a future major
version, once the `maven-4.0.x` deprecation cycle has had time to propagate.
## Related
- MNG-5530 — original `MojoExecutionScope` introduction (ThreadLocal, 2012)
- #13827 — thread-safety discussion that surfaced this gap
-
`impl/maven-core/src/main/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeModule.java`
— commented-out binding
-
`impl/maven-impl/src/main/java/org/apache/maven/impl/di/MojoExecutionScope.java`
— no `createProxy()` path
- `impl/maven-impl/src/main/java/org/apache/maven/impl/di/SessionScope.java`
— has `createProxy()` for comparison
--
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]