gnodet opened a new issue, #13644: URL: https://github.com/apache/maven/issues/13644
## Summary Move Maven 4 plugin descriptor generation into maven-core itself, using a JSR 269 annotation processor instead of the external maven-plugin-plugin. This would simplify the plugin development experience and eliminate the bootstrap problem where building a Maven plugin requires the maven-plugin-plugin (itself a Maven plugin). ## Motivation - **Co-evolution** — Maven 4 annotations (`@Mojo`, `@Parameter`, `@Execute`, `@After`, `@Resolution`), the descriptor Modello model, and the reader/writer already live in maven-core. The generation step is the only piece that remains external. - **Simpler toolchain** — Maven 4 plugin authors would get descriptor generation "for free" without configuring maven-plugin-plugin. The processor auto-activates when `@Mojo` is on the classpath. - **Bootstrap problem** — The current circular dependency (building a plugin requires a plugin) goes away. - **Reduced dependencies** — The current maven-plugin-tools pipeline uses ASM for class scanning and JavaParser (~3MB) for Javadoc extraction. An annotation processor needs neither — it sees annotations directly via the compiler API and accesses Javadoc via `Elements.getDocComment()`. ## What already exists in maven-core - `api/maven-api-core` — Maven 4 annotations with `@Retention(RUNTIME)` - `api/maven-api-plugin` — Modello-generated `PluginDescriptor`, `MojoDescriptor`, `Parameter` model + StAX reader/writer - `impl/maven-impl` — `DefaultPluginXmlFactory` for reading/writing descriptor XML ## Proposed approach ### JSR 269 Annotation Processor Create a new module (e.g., `impl/maven-plugin-processor`) containing a `javax.annotation.processing.AbstractProcessor` that: 1. **Scans** for classes annotated with `@Mojo` (v4: `org.apache.maven.api.plugin.annotations.Mojo`) 2. **Extracts metadata** from annotation attributes (`name`, `defaultPhase`, `requiresDependencyResolution`, `requiresProject`, etc.) and from `@Parameter`, `@Execute`, `@After`, `@Resolution` annotations on fields/methods 3. **Extracts descriptions** from Javadoc via `Elements.getDocComment()` — no JavaParser dependency needed 4. **Builds** the Modello-generated `PluginDescriptor` model directly 5. **Writes** `META-INF/maven/plugin.xml` using the existing `PluginDescriptorStaxWriter` via the `Filer` API 6. **Generates factory classes** — v4 mojos need `*Factory` wrapper classes annotated with `@Named` for DI discovery; these can be generated via the `Filer` API (source generation) instead of ASM bytecode generation 7. **Generates DI index** — writes the `org.apache.maven.api.di.Inject` service index file ### Build integration - Wire the processor into the `maven-plugin` packaging lifecycle so it runs automatically during compilation - Auto-activation via `META-INF/services/javax.annotation.processing.Processor` ### Scope - **Maven 4 plugins only** — no v3 annotation support needed - **maven-plugin-plugin stays** for Maven 3 plugin compat, help mojo generation, and advanced use cases - **maven-plugin-report-plugin stays** for site documentation generation ## Benefits | Aspect | Current (maven-plugin-tools) | Proposed (annotation processor) | |--------|----|----| | Extra dependencies | ASM + JavaParser (~3MB) | None (compiler API) | | Javadoc access | JavaParser source parsing | `Elements.getDocComment()` | | When it runs | `process-classes` phase (post-compile) | During compilation | | Configuration needed | Plugin declaration in POM | Auto-activates | | Code size | ~2500 lines (extractor + generator) | Significantly less | _Claude Code on behalf of Guillaume Nodet_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
