gnodet opened a new pull request, #13094:
URL: https://github.com/apache/maven/pull/13094

   ## Problem
   
   Three major Java IDEs independently override the same internal Maven 
component — `PluginDependenciesResolver` — for identical reasons:
   
   | IDE | Class | Approach |
   |-----|-------|----------|
   | IntelliJ IDEA | `Maven40PluginDependenciesResolver` | implements interface 
directly, `@Priority(10)` |
   | Eclipse m2e | `EclipsePluginDependenciesResolver` | extends 
`DefaultPluginDependenciesResolver` |
   | NetBeans | `NbPluginDependenciesResolver` | extends 
`DefaultPluginDependenciesResolver` |
   
   The root cause: m2e's source still carries the original comment from 2009:
   
   > Plugin realms are cached and there is currently no way to purge cached 
realms due to MNG-4194. Workspace plugins cannot be cached, so we disable this 
until MNG-4194 is fixed.
   
   `DefaultPluginRealmCache` is `@Singleton`. Plugin realms cannot be purged 
within a session. If the IDE workspace reader resolves a plugin, the cached 
realm becomes stale when workspace sources change. The only available 
workaround is to disable the IDE workspace reader during plugin resolution — 
which requires overriding an internal component.
   
   This was raised in the Maven dev list: [\[DISCUSS\] No supported extension 
point for plugin/extension resolution (in 
IDEs)?](https://lists.apache.org/thread/mtt7kg632lfs2hxcx0nv9bn4omkgbvt6)
   
   ## Solution
   
   Introduce a proper SPI in `maven-api-spi`:
   
   ```java
   package org.apache.maven.api.spi;
   
   public interface WorkspaceReader extends SpiService {
       Optional<Path> findArtifact(Artifact artifact);
       List<String> findVersions(Artifact artifact);
   
       default boolean isApplicableForPluginResolution() {
           return true;
       }
   }
   ```
   
   - Uses Maven 4 API types exclusively — no `maven-resolver-api` dependency 
required
   - `isApplicableForPluginResolution()` lets IDE integrators opt their reader 
out of plugin resolution without touching any internal component
   - `SpiWorkspaceReaderAdapter` bridges SPI implementations into the resolver 
workspace reader chain
   - `DefaultPluginDependenciesResolver` filters out non-applicable readers 
when building plugin sessions
   
   ## Migration for IDE integrators
   
   Instead of extending `DefaultPluginDependenciesResolver`:
   
   ```java
   // BEFORE (internal, fragile)
   @Named @Singleton
   class MyIdePluginDependenciesResolver extends 
DefaultPluginDependenciesResolver {
       @Override public Artifact resolve(Plugin plugin, ...) {
           try (var d = myWorkspaceReader.disable()) {
               return super.resolve(plugin, ...);
           }
       }
   }
   
   // AFTER (SPI, stable)
   @Named
   class MyIdeWorkspaceReader implements 
org.apache.maven.api.spi.WorkspaceReader {
       @Override public Optional<Path> findArtifact(Artifact artifact) { ... }
       @Override public List<String> findVersions(Artifact artifact) { ... }
       @Override public boolean isApplicableForPluginResolution() { return 
false; }
   }
   ```
   
   ## Changes
   
   - `maven-api-spi`: new `WorkspaceReader` SPI interface
   - `maven-core`: `SpiWorkspaceReaderAdapter` bridges SPI → resolver; 
`DefaultMaven` injects SPI readers; `DefaultPluginDependenciesResolver` filters 
them per plugin session
   - IT `mng-8766`: verifies SPI reader with 
`isApplicableForPluginResolution()=false` is not called during plugin resolution


-- 
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]

Reply via email to