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/09/21 09:01:27 UTC

[I] [DISCUSSION] Overall plan for classloader improvements in Maven 4.1 [maven]

gnodet opened a new issue, #13223:
URL: https://github.com/apache/maven/issues/13223

   ## Overview
   
   This issue tracks the overall plan for addressing Maven's classloading architecture problems. The full design document is at: https://gist.github.com/gnodet/fef0571deb83280f1df60e7cce1307a1
   
   ## Problem Statement
   
   Maven's classloading architecture has several distinct but related problems:
   
   1. **Global-only exports** — `META-INF/maven/extension.xml` `exportedPackages`/`exportedArtifacts` are injected into *all* plugin/extension realms via `CoreExports`. No per-consumer scoping.
   
   2. **No import control for plugins/extensions** — plugins are passive recipients of whatever core globally exported. No way to say "I need package X in *my* realm only" (see #8997 / MNG-7921, MNG-7955).
   
   3. **`maven.ext.class.path` gap** — entries on that system property bypass `extension.xml` discovery; their exports are silently ignored (see #10506 / MNG-8112, PR #13101 — currently targeting the wrong class).
   
   4. **JPMS vs. unnamed module world** — PR #11029's `META-INF/maven/module-access` only helps named JPMS modules. The vast majority of plugins live in the unnamed module world and have no equivalent.
   
   5. **Classworlds not owned** — `plexus-classworlds` is an external dependency Maven cannot evolve.
   
   ## Solution Layers
   
   ### Layer 0 — Own the classloading stack (prerequisite)
   
   Finish PR #11029: internalize `plexus-classworlds` as `impl/maven-classworlds` + `api/maven-api-classworlds`. All subsequent layers depend on Maven owning these types.
   
   ### Layer 1 — Per-realm import descriptor
   
   Extend `META-INF/maven/extension.xml` with import and strategy declarations so plugins/extensions can declare what they need imported into **their own realm only**:
   
   ```xml
   <extension>
     <!-- EXISTING: what this artifact exports to ALL other realms -->
     <exportedPackages>...</exportedPackages>
     <exportedArtifacts>...</exportedArtifacts>
   
     <!-- NEW: what this plugin/extension needs imported into ITS OWN realm only -->
     <importedPackages>
       <importedPackage>org.slf4j</importedPackage>
       <importedPackage>com.google.inject</importedPackage>
     </importedPackages>
     <importedArtifacts>
       <importedArtifact>com.google.inject:guice</importedArtifact>
     </importedArtifacts>
   
     <!-- NEW: classloader loading strategy -->
     <classLoaderStrategy>self-first</classLoaderStrategy>
   </extension>
   ```
   
   Key design decisions:
   - `importedPackages`/`importedArtifacts` restricted to packages already in `CoreExports` — plugins cannot reach core internals
   - Descriptor read from primary artifact JAR only (not transitives) — avoids resolution chicken-and-egg
   - `classLoaderStrategy` in `extension.xml` is the artifact-level default; `.mvn/extensions.xml` `<classLoadingStrategy>` remains the project-level override
   
   Solves #8997 (MNG-7921) and MNG-7955.
   
   ### Layer 2 — Non-JPMS module access control
   
   Extend the same descriptor with module access for plugins in the unnamed module world:
   
   ```xml
   <extension>
     ...
     <moduleAccess>
       <!-- targeted at this realm's classloader only, not ALL-UNNAMED -->
       <addOpens>java.base/sun.nio.ch</addOpens>
       <addExports>jdk.internal.misc/jdk.internal.misc</addExports>
     </moduleAccess>
   </extension>
   ```
   
   Subsumes and unifies PR #11029's `META-INF/maven/module-access` into a single descriptor.
   
   ### Layer 3 — Fix `maven.ext.class.path` (replaces PR #13101)
   
   In `PlexusContainerCapsuleFactory` (`o.a.maven.cling.invoker`, `impl/maven-cli` — **not** `MavenCli` in deprecated `compat/maven-embedder`): discover `extension.xml` from `maven.ext.class.path` entries, deduplicate by canonical path, include exports in `CoreExports`.
   
   ## Component Map
   
   | Component | Change |
   |---|---|
   | `api/maven-api-classworlds` | New module: public ClassWorld/ClassRealm/Strategy API (Layer 0 / #11029) |
   | `impl/maven-classworlds` | New module: inlined classworlds implementation (Layer 0 / #11029) |
   | `impl/maven-core` `ExtensionDescriptor` | Add: importedPackages, importedArtifacts, classLoaderStrategy, moduleAddOpens, moduleAddExports |
   | `impl/maven-core` `ExtensionDescriptorBuilder` | Add: parsing of the five new elements |
   | `impl/maven-core` `DefaultClassRealmManager` | Apply per-realm descriptor: targeted imports, module access, strategy |
   | `impl/maven-cli` `PlexusContainerCapsuleFactory` | Fix maven.ext.class.path discovery with path dedup |
   | `compat/maven-embedder` | **No new logic** — deprecated |
   
   ## Sequencing
   
   1. **Layer 0** — finish #11029 (classworlds internalization)
   2. **Layer 3** — rework #13101 targeting `impl/maven-cli` only
   3. **Layer 1** — descriptor import/strategy extension, core of the feature
   4. **Layer 2** — module access, follows layer 1, same descriptor format
   
   ## Related issues / PRs
   
   - #11029 — Internalize plexus-classworlds (Layer 0)
   - #13101 — Honor export descriptors from extension classpath (Layer 3, needs rework)
   - #8997 — Allow plugins to control classpath extensions (MNG-7921, addressed by Layer 1)
   - #10506 — MNG-8112 (addressed by Layer 3)
   - MNG-7955 — Plugins should be allowed some control over imported packages (addressed by Layer 1)
   


-- 
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.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Overall plan for classloader improvements in Maven 4.1 [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on issue #13223:
URL: https://github.com/apache/maven/issues/13223#issuecomment-6293014257

   _Claude Code on behalf of Guillaume Nodet_
   
   Updated Layer 0b, Design Principle, and Component Map to reflect design discussion. Key changes:
   
   1. **Single `Realm` interface** — `classLoader()` + `moduleLayer()` + `lookup()`, used uniformly at all levels: `session.realm()`, `project.realm()`, `plugin.realm()`. Replaces the previous `PluginRealm`-only design. Module layers are not plugin-specific (extensions and core can also use them).
   
   2. **Dropped `@ProjectScoped`** — the project realm's injector lifecycle is the scope boundary. A scope annotation would require per-thread binding for concurrent builds — TCCL under a different name.
   
   3. **Composed Lookups, not parent/child injectors** — plugin realms do not inherit project components. Each realm's `lookup()` is composed from explicit sources, matching classloader import semantics.
   
   4. **Component import/export** — `exportedComponents` in `extension.xml` parallel to `exportedPackages`; `requiredExtensions` in `plugin.xml` bridges both class and component visibility. Project-level import is implicit via `<build><extensions>`.
   
   5. **Explicit context passing replaces TCCL** — `project.realm().lookup().lookup(PackagingRegistry.class).require(id)` instead of TCCL swap + global lookup.
   
   6. **PR #13625 alignment** — `PluginRealm` from #13625 should be renamed to `Realm` and generalized. Its TCCL-based `RealmLookup` is a correct transitional implementation.
   
   7. **Added #13570 to related issues** — tactical TCCL-based fix that will be superseded by Layer 0b realm Lookups.


-- 
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: [I] [DISCUSSION] Overall plan for classloader improvements in Maven 4.1 [maven]

Posted by "laeubi (via GitHub)" <gi...@apache.org>.
laeubi commented on issue #13223:
URL: https://github.com/apache/maven/issues/13223#issuecomment-6057986777

   I must confess that the 
   
   ```
   <exportedPackages>...</exportedPackages>
   <exportedArtifacts>...</exportedArtifacts>
   ```
   
   always is/was confusing here as they most often seem to match and there is no clear whats the difference.
   
   I therefore would propose to not reuse that pattern and maybe just treat this as legacy and maybe allow a more semantic thing like
   
   ```
   <exports>
     <artifact>
        ...
        <packages>
          <package>...</package>
        <packages>
     </artifact>
   </exports>
   ```
   
   The same applies to imports, with an important distinction. While now I can declare *that* I want to import something but
   
   - Why do I need to know the artifact and not only package name?
   - What if two extension both export the same artifact/package what one will win or can I even control with something like `provider=G:A`
   
   Next thing that is not considered right now at all:
   I found it always limiting that the *plugin* needs to declare the export (and it must be declared as an extension) leading to the quite strange situation that Tycho has a [tycho-maven-plugin](https://github.com/eclipse-tycho/tycho/tree/main/tycho-maven-plugin) that sole purpose is to be added as a "plugin" but never is providing a mojo or do anything more than being responsible for the exports.
   
   Instead it would be much more sensible if the jar itself could declare such descriptor (e.g. in case of Tycho [tycho-spi](https://github.com/eclipse-tycho/tycho/tree/main/tycho-spi)) that then would be shared. This would allow a plugin to declare a spi artifact that then can be used to share the classes. At best just having it as a dependency then would give me appropriate automatic imports somehow (maybe generated or in runtime).


-- 
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: [I] [DISCUSSION] Overall plan for classloader improvements in Maven 4.1 [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on issue #13223:
URL: https://github.com/apache/maven/issues/13223#issuecomment-6165463728

   _Claude Code on behalf of Guillaume Nodet_
   
   ## Layer 0 implementation — PR stack
   
   Layer 0 (internalize plexus-classworlds) has been split into three incremental PRs:
   
   ### PR A — #13490: Internalize plexus-classworlds and expose stable API
   - Forks `plexus-classworlds` 2.x into `impl/maven-classworlds`
   - New `api/maven-api-classworlds` module with stable `ClassWorld`, `ClassRealm`, `Strategy`, exceptions under `org.apache.maven.api.classworlds`
   - Replaces the external `plexus-classworlds` dependency across all modules
   - Backward-compatible: the `org.codehaus.plexus.classworlds` package structure is preserved in `impl/maven-classworlds`, so Sisu and embedders continue to work unchanged
   
   ### PR B — #13491: Load JLine on module-path for targeted `--enable-native-access`
   - Builds on #13490
   - Moves JLine JARs to `lib/modules/` and loads them on the JPMS module-path via `m2.conf`
   - Replaces the broad `--enable-native-access=ALL-UNNAMED` with targeted grants to `org.jline.terminal.ffm` and `org.jline.nativ`
   - Graceful fallback: JDKs that cannot read the module descriptors continue with classpath loading
   
   ### PR C — #13494: Per-plugin JPMS ModuleLayer support
   - Builds on #13490 (independent of #13491)
   - Plugins can opt in via `<modular>true</modular>` in their plugin descriptor
   - Plugin JARs and dependencies are resolved into an isolated per-plugin `ModuleLayer` via `Configuration.resolveAndBind()` + `defineModulesWithOneLoader()`
   - No fallback — a modular plugin that cannot be loaded as a module causes a hard `ModuleLayerCreationException`
   - `ClassRealm` gains `getModuleLayer()`, `isModular()`, `addExports()`, `addOpens()` for module access control
   - `PluginRealmCache` keys encode the `modular` flag
   
   All three PRs compile and the classworlds unit tests pass. CI is green on #13490.


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