gnodet opened a new pull request, #12529:
URL: https://github.com/apache/maven/pull/12529
## Summary
Adds an integration test demonstrating the **"compile for 3, enhance for
4"** plugin pattern — a Maven plugin that:
- Compiles against Maven 3.9.x API (`maven-plugin-api`, `maven-core`)
- Optionally uses Maven 4's typed API (`Session`, `Project`) at runtime
- Falls back gracefully on Maven 3 — no crashes, no Maven 4 data leaks
### Architecture
```
ProjectInfoMojo.java ← NO Maven 4 imports (loads on Maven 3)
│
│ try { Maven4Enhancer.tryEnhance(...) }
│ catch (NoClassDefFoundError) { /* Maven 3 path 1 */ }
│
├── Maven4Enhancer.java ← imports Session, Project (real typed API)
└── MavenRuntimeDetector.java ← one reflection call for
MavenSession.getSession() bridge
```
### Key design points
- **One reflection call**: only `MavenSession.getSession()` uses reflection
— it's the bridge method added by Maven 4's compat module that doesn't exist on
Maven 3
- **Everything else is typed**: `session.getMavenVersion()`,
`session.getRootDirectory()`, `session.getProjects()`, etc. — direct,
compile-time checked
- **Two Maven 3 fallback paths**:
1. `NoClassDefFoundError` — Maven 4 API classes absent from classpath
2. API jar resolved from Central but `getSession()` bridge absent —
handled in `tryEnhance()`
### Verified on both runtimes
| Runtime | `[MVN3]` tags | `[MVN4]` tags | Detection |
|---------|:-----------:|:-----------:|-----------|
| Maven 3.9.16 | ✅ all 5 | ✅ none | `[RUNTIME] Maven 3` |
| Maven 4.1.0-SNAPSHOT | ✅ all 5 | ✅ all 10 | `[RUNTIME] Maven 4` |
## Test plan
- [x] IT passes on Maven 4 (`mvn verify -Prun-its
-Dits.test=MavenITDualApiPluginTest`)
- [x] Plugin builds and runs correctly on Maven 3.9.16 (manual test)
- [x] No `[MVN4]` data emitted on Maven 3
- [x] All `[MVN4]` data emitted on Maven 4
🤖 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]