gnodet-bot commented on code in PR #13350:
URL: https://github.com/apache/maven/pull/13350#discussion_r4552706693


##########
impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java:
##########
@@ -75,17 +84,42 @@
 public class DefaultPluginDependenciesResolver implements 
PluginDependenciesResolver {
     private static final String REPOSITORY_CONTEXT = 
org.apache.maven.api.services.RequestTrace.CONTEXT_PLUGIN;
 
+    private static final String MANAGED_DEPENDENCIES_KEY =
+            DefaultPluginDependenciesResolver.class.getName() + 
".managedDependencies";
+
+    private static final Set<String> EXCLUDED_FROM_CORE_MANAGED_DEPENDENCIES = 
Set.of(
+            "org.slf4j:slf4j-api",
+            "javax.inject:javax.inject",
+            "javax.annotation:javax.annotation-api",
+            "org.fusesource.jansi:jansi",
+            "org.codehaus.plexus:plexus-interactivity-api");
+

Review Comment:
   💡 **Nit (re-raised):** `EXCLUDED_FROM_CORE_MANAGED_DEPENDENCIES` still has 
no rationale comments explaining why each artifact is excluded. Without them, 
future maintainers cannot evaluate whether the list is complete or correct.
   
   Suggested approach — add inline comments per entry:
   - `org.slf4j:slf4j-api` — plugins must use their own SLF4J binding; aligning 
to the core version would impose the core's binding choice on the plugin  
   - `javax.inject:javax.inject` / `javax.annotation:javax.annotation-api` — 
JSR-330/JSR-250 APIs must remain resolvable by the plugin's DI container 
independently of Maven's copy  
   - `org.fusesource.jansi:jansi` — ANSI terminal library; not a core API, 
plugins may need a different version  
   - `org.codehaus.plexus:plexus-interactivity-api` — interactive prompt API; 
plugin-specific, not a shared core contract



##########
impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java:
##########
@@ -271,12 +306,32 @@ private DependencyResult resolveInternal(
             request.setRequestContext(REPOSITORY_CONTEXT);
             request.setRepositories(repositories);
             request.setRoot(new 
org.eclipse.aether.graph.Dependency(pluginArtifact, null));
+            Map<String, org.eclipse.aether.graph.Dependency> core =
+                    injectCoreManagedDeps ? getCoreDependenciesMap(session) : 
Collections.emptyMap();
+            if (injectCoreManagedDeps && !core.isEmpty()) {
+                request.setManagedDependencies(new ArrayList<>(core.values()));
+            }
             for (Dependency dependency : plugin.getDependencies()) {
                 org.eclipse.aether.graph.Dependency pluginDep =
                         RepositoryUtils.toDependency(dependency, 
session.getArtifactTypeRegistry());
                 if (!DependencyScope.SYSTEM.is(pluginDep.getScope())) {
                     pluginDep = 
pluginDep.setScope(DependencyScope.RUNTIME.id());
                 }
+                if (injectCoreManagedDeps) {
+                    org.eclipse.aether.graph.Dependency managedDep =
+                            core.get(pluginDep.getArtifact().getGroupId() + ":"
+                                    + pluginDep.getArtifact().getArtifactId());
+                    if (managedDep != null) {
+                        if (!Objects.equals(
+                                pluginDep.getArtifact().getVersion(),
+                                managedDep.getArtifact().getVersion())) {
+                            pluginDep = pluginDep.setArtifact(pluginDep
+                                    .getArtifact()
+                                    
.setVersion(managedDep.getArtifact().getVersion()));
+                        }
+                        pluginDep = pluginDep.setScope(managedDep.getScope());
+                    }

Review Comment:
   💡 **Minor:** Add a brief comment explaining why the scope override is 
unconditional (applies even when version already matches):
   
   ```suggestion
                           pluginDep = 
pluginDep.setScope(managedDep.getScope()); // force provided: core artifact is 
already on Maven's core classloader regardless of what the plugin declared
   ```



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