You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/07/24 08:15:56 UTC
[PR] Add IT for dual-API plugin pattern (compile for Maven 3, enhance for Maven 4) [maven]
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add IT for dual-API plugin pattern (compile for Maven 3, enhance for Maven 4) [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet closed pull request #12529: Add IT for dual-API plugin pattern (compile for Maven 3, enhance for Maven 4)
URL: https://github.com/apache/maven/pull/12529
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add IT for dual-API plugin pattern (compile for Maven 3, enhance for Maven 4) [maven]
Posted by "hboutemy (via GitHub)" <gi...@apache.org>.
hboutemy commented on PR #12529:
URL: https://github.com/apache/maven/pull/12529#issuecomment-5071140835
great test, could be very useful for improved Java Modules support in a few plugins
see https://cwiki.apache.org/confluence/spaces/MAVEN/pages/393677487/Full+Java+Modules+Support+-+Current+State#FullJavaModulesSupportCurrentState-ImplementationstrategyforMaven3vsMaven4support
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org