Repository navigation
Add WorkspaceReader SPI to maven-api-spi - #13094
Conversation
gnodet-bot
left a comment
There was a problem hiding this comment.
Clean SPI design that solves a real pain point for all three major IDE integrators. The adapter pattern is sound, the filtering logic is correct, and the IT covers the critical negative case.
One observation on the IT — see inline.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
I'm not sure this really solve the issue or is wanted. Instead one more want to be able to purge the cache (so no disabling is actually needed) isn't it? |
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after d1d0447c7a. All prior findings addressed:
- Positive assertion added — the IT now verifies
[SPI-WR] findArtifact(appears in logs during regular resolution, confirming the SPI reader participates in the main session. - Discovery fix — switched from constructor-injected
List<WorkspaceReader>tolookup.lookupList(), which correctly picks up beans registered by core extensions (loaded after container bootstrap). This was the root cause of the CI failure. - Test updated —
DefaultMavenSessionScopeTestupdated to match the new constructor signature.
The adapter (SpiWorkspaceReaderAdapter) correctly bridges resolver ↔ API types. LightweightApiArtifact.key() matches the default Artifact.key() contract. The filtering in DefaultPluginDependenciesResolver creates a new session/chain without mutating the original — thread-safe.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
Thanks @laeubi, you're right on both counts. The approach has been reworked in 44e96719ff:
The reasoning: IDEs trust their own build — if they've rebuilt a plugin from the workspace, they want it used. The right API is cache invalidation on demand, not blanket exclusion from resolution. As for the generics of |
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 44e96719ff. The rework based on @laeubi's feedback is a significant improvement — PluginRealmCache.invalidate(Artifact) is the right abstraction (cache invalidation on demand vs. blanket exclusion from resolution).
The SPI interface, adapter, and DI discovery are solid. Two cosmetic issues from the rework — stale <description> elements that still reference the old approach.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 7b734aae0a. Both stale <description> elements fixed exactly as suggested — extension pom now says "IDE workspace artifact resolution" and project pom says "discovered and consulted for artifact resolution."
All prior findings addressed. SPI design, adapter, cache invalidation, and IT remain solid from the previous review.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 8850b59ed8. Good fix — moving SPI reader discovery from doExecute() to setupWorkspaceReader() is correct: core extensions aren't in the container until after buildGraph(), so the earlier lookup.lookupList() call always returned empty. Using getProjectScopedExtensionComponents() is consistent with the legacy WorkspaceReader discovery on the line above.
One stale comment from the previous approach — see inline.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 438208ff5e (spotless formatting).
The formatting fix is fine, but the stale comment from the previous review is still not addressed — see inline.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 8bbf426e4c. Stale comment fixed — now correctly references getProjectScopedExtensionComponents instead of lookupList.
All prior findings from previous reviews are addressed. SPI design, adapter, cache invalidation, and IT remain solid.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 3f224de701 — spotless formatting only (wrapped long comment line in DefaultMaven). No logic change. All prior findings remain addressed.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
3f224de to
b36eba6
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after b36eba696c. The switch from getProjectScopedExtensionComponents() to the maven-di Injector via SpiWorkspaceReadersHolder is the correct fix — SPI components annotated with @org.apache.maven.api.di.Named live in the maven-di layer, not Plexus/SISU, so Plexus lookups always returned empty. The new @Singleton holder receives all named WorkspaceReader bindings via Map<String, WorkspaceReader> injection and is instantiated lazily after buildGraph(), when extension bindings are visible. The META-INF/maven/org.apache.maven.api.di.Inject registration is correct.
No new issues. All prior findings remain addressed.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
b36eba6 to
23fb055
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 23fb055bbc. Two clean fixes:
DefaultMaven— lookup simplified fromlookup.lookup(Injector.class).getInstance(SpiWorkspaceReadersHolder.class)tolookup.lookup(SpiWorkspaceReadersHolder.class). Correct: the holder is@Named @Singletonunder maven-di, bridged to Sisu viaSisuDiBridgeModule, so a plain Plexuslookup()finds it. The comment now accurately describes this mechanism.SpiWorkspaceReadersHolder—@Nullableadded on theMap<String, WorkspaceReader>parameter with a null-safe initialization guard. Correct fix for the zero-readers case: maven-di injectsnullfor an unsatisfiedMap<K,V>binding rather than throwing.
All prior findings remain addressed. No new issues introduced.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 23fb055bbc. The SpiWorkspaceReadersHolder approach is cleaner than the direct Injector access from b36eba696c — using Lookup.lookup() keeps the code consistent with how other components are looked up in DefaultMaven, and the META-INF/maven/org.apache.maven.api.di.Inject registration is the right registration mechanism.
Two issues found:
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 4a192fef92. Both findings from the previous review are addressed:
getReaders()mutable list —Collections.unmodifiableList(readers)is now returned. Correct; the@Nullablepath that initialisesreaderstoCollections.emptyList()already returns an unmodifiable list, so the double-wrap is harmless.StringVersion.compareTo()Javadoc — The new class-level Javadoc is accurate and complete: it calls out the lexicographic limitation, states that the wrapper is used solely for coordinate lookup, and directs implementors toVersionParserwhen ordering matters.
All prior findings from previous reviews remain addressed. The SPI interface, adapter, holder, DI discovery path, and IT are solid.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
Cross-referencing #13499 — Tycho's analysis identified one gap in this PR's Tycho's Worth considering whether Claude Code on behalf of Guillaume Nodet |
|
Cross-referencing #13499 (updated with m2e analysis) — the m2e overrides 5 cache components ( Claude Code on behalf of Guillaume Nodet |
|
This PR currently covers two concerns that now have separate tracking sub-issues under #13499:
These could be split into separate PRs to allow independent review and merging, or kept together if that's simpler — just noting the tracking structure for visibility. Claude Code on behalf of Guillaume Nodet |
4a192fe to
4d3fa6a
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 4d3fa6ab43. All previous findings are resolved ✅. One new issue with the findModel() addition.
SpiWorkspaceReaderAdapter doesn't implement MavenWorkspaceReader — findModel() is dead API
MavenChainedWorkspaceReader.findModel() iterates the reader chain and only delegates to readers that are instanceof MavenWorkspaceReader. Since SpiWorkspaceReaderAdapter implements only org.eclipse.aether.repository.WorkspaceReader, any SPI implementation of findModel() will be silently ignored — the new method is declared in the SPI but unreachable through the workspace reader chain.
See inline comment for the fix.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
💡 Rebase heads-up —
After rebasing onto current master, the class will fail to compile: When rebasing, rename:
This comment was generated by an AI agent, Hermès on behalf of @gnodet. |
|
Rebase needed before merge: The PR branch's merge base ( This comment was generated by an AI agent, Hermès on behalf of @gnodet. |
d6a5127 to
f94a322
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Previous findings are all addressed. LGTM.
- ✅ Deprecated API (
getGroupId()/getArtifactId()/getVersion()) replaced with noun-style accessors throughoutTestSpiWorkspaceReader—findVersions()andisSyntheticArtifact()now useartifact.groupId(),artifact.artifactId(),artifact.version().toString()
No new issues introduced. The SPI interface, adapter, DI wiring, and integration test are solid.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier reviews — previous findings all remain addressed ✅. One new issue introduced by this push.
TestSpiWorkspaceReader is missing imports — compilation failure
The push removed four imports from TestSpiWorkspaceReader.java while updating findModel() to return Optional<Model> instead of Optional<Path>. However, findArtifact() was not changed and still uses the now-absent types:
Path jar = Files.createTempFile(...)— needsjava.nio.file.Pathandjava.nio.file.Filestry (OutputStream os = Files.newOutputStream(jar))— needsjava.io.OutputStream} catch (IOException e)— needsjava.io.IOException
The current HEAD (a49790c5) file has imports:
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Missing (removed but still required):
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;The extension module will fail to compile, breaking the IT. Add the four imports back.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review after 4ca8b5ea. The missing-imports issue flagged in my previous review is resolved — 4ca8b5ea restores java.io.IOException, java.io.OutputStream, java.nio.file.Files, and java.nio.file.Path to TestSpiWorkspaceReader. One follow-on nit.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
All 17 prior review threads are resolved. The two latest commits correctly address the last CHANGES_REQUESTED findings:
- a49790c — Refactors
findModel()to returnOptional<Model>directly from the SPI, removing the XML parsing indirection and eliminating the previous exception-swallowing concern.SpiWorkspaceReaderAdapterbridges cleanly via.orElse(null)to the nullableMavenWorkspaceReadercontract. - 4ca8b5e — Restores the four missing imports (
IOException,OutputStream,Files,Path) inTestSpiWorkspaceReader.java; all are consumed byfindArtifact().
No new issues introduced.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet
left a comment
There was a problem hiding this comment.
Re-review after 8248b061. This commit correctly diagnoses and fixes the root cause of the IT failure.
Why the fix is right: Core extensions declared in .mvn/extensions.xml are wired into the global DI container before project scanning begins (before buildGraph() is called). The previous approach only discovered SPI readers after buildGraph() via setupWorkspaceReader(). When a project declares a workspace-resolved dependency, Maven resolves its POM during buildGraph() — at which point the SPI reader chain was empty, so the POM fetch fell through to the remote repository and failed.
The two-phase registration is correct:
- Before
buildGraph():lookup.lookupList(WorkspaceReader.class)against the global container picks up core extension readers and adds them immediately - After
buildGraph()insetupWorkspaceReader():getProjectScopedExtensionComponents()picks up project-level extension readers; the identity deduplication viaIdentityHashMapprevents double-wrapping core-extension readers already registered in step 1
The deduplication logic is correct: workspaceReaders already contains the step-1 adapters (copied in via chainedWorkspaceReader.getReaders() iteration), so the IdentityHashMap is fully populated before the getProjectScopedExtensionComponents loop.
One cosmetic nit — see inline.
All prior findings remain addressed. The SPI design, adapter, and IT are solid.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
9966751 to
cf465ef
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-reviewed after latest squash commit — all prior findings have been addressed. The SPI is well-structured, test coverage is appropriate, and the LightweightApiArtifact limitation is clearly documented.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
63bf990 to
2152c09
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
The IT test class uses @since 4.1.0 while all production code in this PR uses @since 4.2.0.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier reviews — previous findings are all addressed ✅.
One new issue introduced by the latest commit (d46eb028).
getSpiWorkspaceReadersFromInjector() catches LookupException but InjectorImpl throws DIException — standard builds will fail
InjectorImpl.doGetCompiledBinding() throws DIException (extends RuntimeException) when no bindings exist for a List<WorkspaceReader> key — the if (res2 != null) branch is skipped when there are no registered implementations, falling through to the throw new DIException(...) at line 310. DIException is NOT a subtype of LookupException (DIException extends RuntimeException; LookupException extends MavenException extends RuntimeException — sibling hierarchies). The catch (LookupException e) block will not intercept it.
This means every standard Maven build without an SPI workspace reader registered — which is effectively all Maven builds today — will fail with an uncaught DIException propagating through doExecute().
Fix: catch Exception (or at least RuntimeException | LookupException) — see inline suggestion.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Previous finding addressed — @since annotation is now 4.2.0 across all 4 sites. LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
3163966 to
1b592c6
Compare
1b592c6 to
f97dd01
Compare
Problem
Three major Java IDEs independently override the same internal Maven component —
DefaultPluginDependenciesResolver— for identical reasons: their workspace reader must not participate in plugin resolution, because plugin realms are cached byDefaultPluginRealmCache(@Singleton) and cannot be purged within a session. Resolving plugins from the IDE workspace causes stale classloaders whenever workspace sources change.This was raised on the Maven dev list: [DISCUSS] No supported extension point for plugin/extension resolution (in IDEs)?
Solution
Introduce a proper SPI in
maven-api-spi:maven-resolver-apidependency requiredfindModel(Artifact)returns a pre-builtModeldirectly (not a path to parse): IDE integrators construct the model from their own sources (e.g. Eclipse manifests) without writing an intermediate XML file. The model bypassesModelProcessorentirely and is consistent withReactorReader, which also returns an in-memory model.SpiWorkspaceReaderAdapterimplementsMavenWorkspaceReader, bridging SPI implementations into the resolver workspace reader chain (includingfindModel()dispatch viaMavenChainedWorkspaceReader)buildGraph()via the maven DIInjector(see below), so they participate in POM resolution as well as artifact resolutionbuildGraph()insetupWorkspaceReader(), with identity-based deduplication to avoid wrapping the same reader twiceDiscovery mechanism
SPI implementations registered as core extensions (
.mvn/extensions.xml) are discovered by callingInjector.getInstance(Key<List<WorkspaceReader>>)rather thanlookup.lookupList().The reason:
BridgeInjectorImplinSisuDiBridgeModulestores the GuiceBinderfrom the initial containerconfigure()phase. WhenPlexusContainer.discoverComponents()callsInjector.discover(extensionRealm)for each core extension later, new beans are correctly registered intoInjectorImpl's internal binding map, but the bridge into Guice/Sisu via the stored (now inactive)Bindermay not succeed. A plainlookupList()reads from Guice/Sisu and returns nothing for these beans. Reading directly from theInjectorvia theList<T>key is the reliable path.Changes
maven-api-spi: newWorkspaceReaderSPI interface withfindArtifact(),findVersions(), and defaultfindModel()returningOptional<Model>maven-core:SpiWorkspaceReaderAdapterbridges SPI →MavenWorkspaceReadermaven-core:DefaultMavendiscovers core-extension SPI readers beforebuildGraph()viagetSpiWorkspaceReadersFromInjector(), and project-scoped SPI readers afterbuildGraph()insetupWorkspaceReader()(with dedup)mng-8766: verifies SPI reader discovery as a core extension,findArtifact()consultation, and end-to-endfindModel()wiring using a fully synthetic artifact that does not exist in any repositorySolves #13515