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

   <!--
   Please open pull requests against one of the following branches:
   
   - master — default target for all changes (new features + bug fixes).  
     If the change should also go to maven-4.0.x, request a backport in the PR.
   
   - maven-3.10.x — target for 3.x changes (new features + bug fixes).  
     If the change should also go to maven-3.9.x, request a backport in the PR.
     maven-3.9.x should receive only serious bug fixes, as it is approaching 
EOL.
   
   Backports are typically handled by maintainers; 
   however, after agreement you may open a separate backport PR to the target 
maintenance branch.
   -->
   
   ## What problem does this PR fix?
   
   Companion backport of #13730 to `maven-4.0.x`.
   Fixes [MNG-8298](https://issues.apache.org/jira/browse/MNG-8298) / 
https://github.com/apache/maven/issues/10527 on `maven-4.0.x`.
   
   Following PR #1336 ([MNG-8176] Restrict classloader for Maven 4 plugins), 
Maven 4 plugins are restricted to the `maven.api.v4` realm, which only imported 
`org.apache.maven.api` and `org.slf4j`.
   
   When executing Maven 4 plugins such as 
`org.apache.maven.plugins:maven-resources-plugin:4.0.0-beta-2-SNAPSHOT`, 
dependencies like `org.apache.maven.shared:maven-filtering` use 
`org.sonatype.plexus:plexus-build-api` (e.g., `BuildContext`, 
`DefaultBuildContext`, `ThreadBuildContext`). `DefaultBuildContext` extends 
`org.codehaus.plexus.logging.AbstractLogEnabled`.
   
   Because `plexus-container-default` is marked `<scope>provided</scope>` in 
`plexus-build-api`, it is not packaged into the plugin realm and relies on 
Maven Core to provide it. Because `maven.api.v4` did not export 
`org.codehaus.plexus.logging`, looking up or instantiating these classes fails 
at runtime with:
   
   ```
   [ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-resources-plugin:4.0.0-beta-2-SNAPSHOT:resources 
(default-resources) on project a: Execution default-resources of goal 
org.apache.maven.plugins:maven-resources-plugin:4.0.0-beta-2-SNAPSHOT:resources 
failed: Unable to lookup Mojo: Error while initializing binding 
BindingToConstructor[@Named(\"org.apache.maven.plugins:maven-resources-plugin:4.0.0-beta-2-SNAPSHOT:resources\")
 ResourcesMojoFactory][]: Error while initializing binding 
BindingToConstructor[@Named 
DefaultMavenResourcesFiltering][Dependency[key=BuildContext, optional=false], 
Dependency[key=MavenFileFilter, optional=false]]: Error while initializing 
binding BindingToConstructor[@Named 
DefaultMavenFileFilter][Dependency[key=BuildContext, optional=false]]: Failed 
to call method static org.sonatype.plexus.build.incremental.BuildContext 
org.apache.maven.plugins.resources.Providers.buildContext(): 
org/codehaus/plexus/logging/AbstractLogEnabled: org.codehaus.plexus.lo
 gging.AbstractLogEnabled -> [Help 1]
   ```
   
   ## Solution
   
   1. In `DefaultClassRealmManager.java`, export `org.codehaus.plexus.logging` 
to `maven4ApiRealm` (`apiV4Imports.put("org.codehaus.plexus.logging", 
containerRealm);`). This allows plugins and shared components (like 
`plexus-build-api`) extending `AbstractLogEnabled` or using Plexus `Logger` to 
resolve properly and route logging through Maven's SLF4J logger.
   2. In `DefaultClassRealmManagerTest.java`, add `testMaven4ApiRealm` to 
verify that `maven4ApiRealm` imports `org.apache.maven.api`, `org.slf4j`, and 
`org.codehaus.plexus.logging` from the container realm while keeping 
unrestricted core packages unexposed.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [x] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


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