This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new f6d1bca527 fix: filter SPI providers by classloader visibility to
prevent reactor leaks
f6d1bca527 is described below
commit f6d1bca52717b46ee84183f746adf75b4cfca321
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Nov 5 17:15:46 2026 +0100
fix: filter SPI providers by classloader visibility to prevent reactor leaks
`DefaultExtensibleEnumRegistry.lookup()` feeds on `Lookup.lookupList()`
which
returns all SISU-registered providers globally. In a parallel reactor build,
an extension loaded for one module leaks its PackagingProvider (and other
SPI
registries) into sibling modules, causing "Unknown packaging: app-client" on
projects that don't declare that extension.
- Add `isVisibleFrom(provider, tccl)` in ExtensibleEnumRegistries: walks
the classloader hierarchy and checks Plexus ClassRealm.getImportRealms()
via ClassValue-cached reflection to determine whether a provider's realm
is imported into the current project's realm
- Add 4-arg constructor to DefaultExtensibleEnumRegistry accepting Lookup +
providerType; override lookup() to filter dynamic providers through
isVisibleFrom() before returning a match
- DefaultPackagingRegistry uses the new constructor to enable filtered
lookup
- DefaultExtensibleEnumRegistryTest covers the visibility filter,
hidden-class
providers, and null-classloader edge cases
- MavenITgh13306PackagingProviderTest verifies isolation in a reactor with
-T 2
---
.../internal/impl/DefaultPackagingRegistry.java | 21 +--
.../maven/impl/ExtensibleEnumRegistries.java | 106 +++++++++++-
.../impl/DefaultExtensibleEnumRegistryTest.java | 187 +++++++++++++++++++++
.../it/MavenITgh13306PackagingProviderTest.java | 59 +++++++
.../gh-13306-packaging-provider/client/pom.xml | 36 ++++
.../gh-13306-packaging-provider/extension/pom.xml | 75 +++++++++
.../maven/its/gh13306/CustomPackagingProvider.java | 40 +++++
.../maven/its/gh13306/CustomTypeProvider.java | 72 ++++++++
.../gh-13306-packaging-provider/reactor/pom.xml | 30 ++++
.../reactor/with-extension/pom.xml | 39 +++++
.../reactor/without-extension/pom.xml | 29 ++++
11 files changed, 683 insertions(+), 11 deletions(-)
diff --git
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultPackagingRegistry.java
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultPackagingRegistry.java
index d93590d4d4..ae0f4ae2dc 100644
---
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultPackagingRegistry.java
+++
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultPackagingRegistry.java
@@ -66,29 +66,30 @@ public class DefaultPackagingRegistry
@Inject
public DefaultPackagingRegistry(Lookup lookup, TypeRegistry typeRegistry,
List<PackagingProvider> providers) {
- super(providers);
+ super(lookup, PackagingProvider.class, providers, new Packaging[0]);
this.lookup = lookup;
this.typeRegistry = typeRegistry;
}
@Override
public Optional<Packaging> lookup(String id) {
- id = id.toLowerCase(Locale.ROOT);
- // TODO: we should be able to inject a Map<String, LifecycleMapping>
directly,
- // however, SISU visibility filtering can only happen when an explicit
- // lookup is performed. The whole problem here is caused by "project
extensions"
- // which are bound to a project's classloader, without any clear
definition
- // of a "project scope"
+ Optional<Packaging> result = super.lookup(id);
+ if (result.isPresent()) {
+ return result;
+ }
+ // Legacy LifecycleMapping fallback: SISU visibility filtering requires
+ // an explicit lookup (project extensions are bound to a project
classloader)
+ String packagingId = id.toLowerCase(Locale.ROOT);
LifecycleMapping lifecycleMapping =
- lookup.lookupOptional(LifecycleMapping.class, id).orElse(null);
+ lookup.lookupOptional(LifecycleMapping.class,
packagingId).orElse(null);
if (lifecycleMapping == null) {
return Optional.empty();
}
- Type type = typeRegistry.lookup(id).orElse(null);
+ Type type = typeRegistry.lookup(packagingId).orElse(null);
if (type == null) {
return Optional.empty();
}
- return Optional.of(new DefaultPackaging(id, type,
getPlugins(lifecycleMapping)));
+ return Optional.of(new DefaultPackaging(packagingId, type,
getPlugins(lifecycleMapping)));
}
private Map<String, PluginContainer> getPlugins(LifecycleMapping
lifecycleMapping) {
diff --git
a/impl/maven-impl/src/main/java/org/apache/maven/impl/ExtensibleEnumRegistries.java
b/impl/maven-impl/src/main/java/org/apache/maven/impl/ExtensibleEnumRegistries.java
index 942a088417..0093a3949d 100644
---
a/impl/maven-impl/src/main/java/org/apache/maven/impl/ExtensibleEnumRegistries.java
+++
b/impl/maven-impl/src/main/java/org/apache/maven/impl/ExtensibleEnumRegistries.java
@@ -18,6 +18,8 @@
*/
package org.apache.maven.impl;
+import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@@ -39,6 +41,7 @@
import org.apache.maven.api.services.DialectRegistry;
import org.apache.maven.api.services.ExtensibleEnumRegistry;
import org.apache.maven.api.services.LanguageRegistry;
+import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.services.PathScopeRegistry;
import org.apache.maven.api.services.ProjectScopeRegistry;
import org.apache.maven.api.spi.DialectProvider;
@@ -52,6 +55,66 @@
public class ExtensibleEnumRegistries {
+ private static final ClassValue<Optional<Method>> GET_IMPORT_REALMS = new
ClassValue<>() {
+ @Override
+ protected Optional<Method> computeValue(Class<?> type) {
+ try {
+ return Optional.of(type.getMethod("getImportRealms"));
+ } catch (NoSuchMethodException | SecurityException e) {
+ return Optional.empty();
+ }
+ }
+ };
+
+ /**
+ * Checks whether a provider is visible from the given classloader.
+ * Providers from project extensions are loaded by extension-specific
classloaders
+ * (realms) that are only imported into the project realm that declared
the extension.
+ * This prevents extension-scoped providers from leaking across reactor
modules
+ * during parallel builds.
+ *
+ * @param provider the SPI provider to check
+ * @param classLoader the classloader to check visibility from (typically
the TCCL)
+ * @return {@code true} if the provider is visible, {@code false} otherwise
+ */
+ public static boolean isVisibleFrom(Object provider, ClassLoader
classLoader) {
+ if (classLoader == null) {
+ return true;
+ }
+ Class<?> providerClass = provider.getClass();
+ ClassLoader providerCl = providerClass.getClassLoader();
+ if (providerCl == null) {
+ return true;
+ }
+ try {
+ if (classLoader.loadClass(providerClass.getName()) ==
providerClass) {
+ return true;
+ }
+ } catch (ClassNotFoundException | LinkageError e) {
+ // Not loadable by name (hidden class, realm-ID import, or broken
link) — check further
+ }
+ for (ClassLoader cl = classLoader; cl != null; cl = cl.getParent()) {
+ if (cl == providerCl) {
+ return true;
+ }
+ }
+ return isImportedRealm(classLoader, providerCl);
+ }
+
+ private static boolean isImportedRealm(ClassLoader classLoader,
ClassLoader providerCl) {
+ return GET_IMPORT_REALMS
+ .get(classLoader.getClass())
+ .map(method -> {
+ try {
+ Collection<?> importedRealms = (Collection<?>)
method.invoke(classLoader);
+ return importedRealms.contains(providerCl);
+ } catch (ReflectiveOperationException | ClassCastException
e) {
+ return false;
+ }
+ })
+ .orElse(false);
+ }
+
@Named
@SessionScoped
public static class DefaultPathScopeRegistry extends
DefaultExtensibleEnumRegistry<PathScope, PathScopeProvider>
@@ -131,16 +194,57 @@ public abstract static class
DefaultExtensibleEnumRegistry<
implements ExtensibleEnumRegistry<T> {
protected final Map<String, T> values;
+ private final Lookup lookup;
+ private final Class<P> providerType;
@SafeVarargs
public DefaultExtensibleEnumRegistry(List<P> providers, T...
builtinValues) {
+ this(null, null, providers, builtinValues);
+ }
+
+ @SafeVarargs
+ public DefaultExtensibleEnumRegistry(
+ Lookup lookup, Class<P> providerType, List<P> providers, T...
builtinValues) {
+ this.lookup = lookup;
+ this.providerType = providerType;
values = Stream.concat(Stream.of(builtinValues),
providers.stream().flatMap(p -> p.provides().stream()))
.collect(Collectors.toUnmodifiableMap(t ->
t.id().toLowerCase(Locale.ROOT), t -> t));
}
+ /**
+ * Looks up an enum value by id, checking dynamic providers before the
static registry.
+ *
+ * <p><b>Cardinality assumption:</b> when dynamic lookup is enabled,
this method iterates
+ * all registered providers and all their values on every call —
O(n·m) where {@code n} is
+ * the number of providers and {@code m} is the average number of
values per provider.
+ * Both are expected to be O(tens) in practice (a handful of SPI
providers, each contributing
+ * a small set of values). This method is <em>not</em> designed for
cardinalities in the
+ * thousands; callers that need to look up the same value repeatedly
in a tight loop should
+ * cache the result themselves.</p>
+ *
+ * <p><b>Classloader visibility:</b> providers contributed by project
extensions are only
+ * visible when the current thread's context classloader can load the
provider's class.
+ * This prevents extension-scoped providers from leaking across
reactor modules during
+ * parallel builds.</p>
+ *
+ * @param id the enum value id, must not be {@code null}
+ * @return the matching value, or {@code Optional.empty()} if not found
+ */
@Override
public Optional<T> lookup(String id) {
- return Optional.ofNullable(values.get(requireNonNull(id,
"id").toLowerCase(Locale.ROOT)));
+ String key = requireNonNull(id, "id").toLowerCase(Locale.ROOT);
+ if (lookup != null && providerType != null) {
+ ClassLoader tccl =
Thread.currentThread().getContextClassLoader();
+ Optional<T> result = lookup.lookupList(providerType).stream()
+ .filter(p -> isVisibleFrom(p, tccl))
+ .flatMap(p -> p.provides().stream())
+ .filter(t ->
key.equals(t.id().toLowerCase(Locale.ROOT)))
+ .findFirst();
+ if (result.isPresent()) {
+ return result;
+ }
+ }
+ return Optional.ofNullable(values.get(key));
}
}
}
diff --git
a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultExtensibleEnumRegistryTest.java
b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultExtensibleEnumRegistryTest.java
new file mode 100644
index 0000000000..b161b7c958
--- /dev/null
+++
b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultExtensibleEnumRegistryTest.java
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.impl;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.maven.api.ExtensibleEnum;
+import org.apache.maven.api.services.Lookup;
+import org.apache.maven.api.spi.ExtensibleEnumProvider;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class DefaultExtensibleEnumRegistryTest {
+
+ private static final TestValue FOO = new TestValue("foo");
+ private static final TestValue BAR = new TestValue("bar");
+ private static final TestValue CUSTOM = new TestValue("custom");
+
+ @Test
+ void lookupFindsBuiltinValues() {
+ var registry = new TestRegistry(List.of(), FOO, BAR);
+ assertSame(FOO, registry.lookup("foo").orElseThrow());
+ assertSame(BAR, registry.lookup("BAR").orElseThrow());
+ }
+
+ @Test
+ void lookupFindsConstructorInjectedProviders() {
+ TestProvider provider = () -> List.of(CUSTOM);
+ var registry = new TestRegistry(List.of(provider));
+ assertSame(CUSTOM, registry.lookup("custom").orElseThrow());
+ }
+
+ @Test
+ void dynamicLookupFindsProjectExtensionProviders() {
+ Lookup lookup = mock(Lookup.class);
+ TestProvider provider = () -> List.of(CUSTOM);
+
when(lookup.lookupList(TestProvider.class)).thenReturn(List.of(provider));
+
+ var registry = new TestRegistry(lookup, List.of());
+ assertSame(CUSTOM, registry.lookup("custom").orElseThrow());
+ }
+
+ @Test
+ void dynamicLookupTakesPriorityOverConstructorInjected() {
+ Lookup lookup = mock(Lookup.class);
+ TestValue builtin = new TestValue("foo");
+ TestValue override = new TestValue("foo");
+ TestProvider dynamicProvider = () -> List.of(override);
+ TestProvider injectedProvider = () -> List.of(builtin);
+
when(lookup.lookupList(TestProvider.class)).thenReturn(List.of(dynamicProvider));
+
+ var registry = new TestRegistry(lookup, List.of(injectedProvider));
+ assertSame(override, registry.lookup("foo").orElseThrow());
+ }
+
+ @Test
+ void dynamicLookupDoesNotRetainProviderAcrossProjects() {
+ Lookup lookup = mock(Lookup.class);
+ TestValue custom = new TestValue("custom");
+ TestProvider provider = () -> List.of(custom);
+ AtomicReference<List<TestProvider>> visible = new
AtomicReference<>(List.of(provider));
+ when(lookup.lookupList(TestProvider.class)).thenAnswer(inv ->
visible.get());
+
+ var registry = new TestRegistry(lookup, List.of());
+
+ assertSame(custom, registry.lookup("custom").orElseThrow());
+ visible.set(List.of());
+ assertTrue(registry.lookup("custom").isEmpty());
+ }
+
+ @Test
+ void fallsBackToBuiltinWhenDynamicLookupFindsNothing() {
+ Lookup lookup = mock(Lookup.class);
+ when(lookup.lookupList(TestProvider.class)).thenReturn(List.of());
+
+ TestValue foo = new TestValue("foo");
+ var registry = new TestRegistry(lookup, List.of(), foo);
+ assertSame(foo, registry.lookup("foo").orElseThrow());
+ }
+
+ // --- isVisibleFrom tests ---
+
+ @Test
+ void visibleFromNullClassLoaderAlwaysReturnsTrue() {
+ TestProvider provider = () -> List.of(CUSTOM);
+ assertTrue(ExtensibleEnumRegistries.isVisibleFrom(provider, null));
+ }
+
+ @Test
+ void visibleFromSameClassLoaderReturnsTrue() {
+ TestProvider provider = () -> List.of(CUSTOM);
+ ClassLoader cl = provider.getClass().getClassLoader();
+ assertTrue(ExtensibleEnumRegistries.isVisibleFrom(provider, cl));
+ }
+
+ @Test
+ void visibleFromChildOfParentClassLoaderReturnsTrue() {
+ TestProvider provider = () -> List.of(CUSTOM);
+ ClassLoader parent = provider.getClass().getClassLoader();
+ ClassLoader child = new URLClassLoader(new URL[0], parent);
+ assertTrue(ExtensibleEnumRegistries.isVisibleFrom(provider, child));
+ }
+
+ @Test
+ void notVisibleFromUnrelatedClassLoader() {
+ TestProvider provider = () -> List.of(CUSTOM);
+ ClassLoader unrelated = new URLClassLoader(new URL[0], null);
+ assertFalse(ExtensibleEnumRegistries.isVisibleFrom(provider,
unrelated));
+ }
+
+ @Test
+ void visibleFromClassRealmThatImportsProviderRealm() {
+ TestProvider provider = () -> List.of(CUSTOM);
+ ClassLoader providerCl = provider.getClass().getClassLoader();
+ FakeClassRealm realm = new FakeClassRealm(Set.of(providerCl));
+ assertTrue(ExtensibleEnumRegistries.isVisibleFrom(provider, realm));
+ }
+
+ @Test
+ void notVisibleFromClassRealmWithoutMatchingImport() {
+ TestProvider provider = () -> List.of(CUSTOM);
+ ClassLoader otherCl = new URLClassLoader(new URL[0], null);
+ FakeClassRealm realm = new FakeClassRealm(Set.of(otherCl));
+ assertFalse(ExtensibleEnumRegistries.isVisibleFrom(provider, realm));
+ }
+
+ record TestValue(String id) implements ExtensibleEnum {}
+
+ interface TestProvider extends ExtensibleEnumProvider<TestValue> {}
+
+ static class TestRegistry extends
ExtensibleEnumRegistries.DefaultExtensibleEnumRegistry<TestValue, TestProvider>
{
+
+ @SafeVarargs
+ TestRegistry(List<TestProvider> providers, TestValue... builtins) {
+ super(providers, builtins);
+ }
+
+ @SafeVarargs
+ TestRegistry(Lookup lookup, List<TestProvider> providers, TestValue...
builtins) {
+ super(lookup, TestProvider.class, providers, builtins);
+ }
+ }
+
+ /**
+ * Simulates a ClassRealm with {@code getImportRealms()} so the
reflection-based
+ * import check can be exercised without depending on plexus-classworlds.
+ */
+ static class FakeClassRealm extends URLClassLoader {
+ private final Collection<ClassLoader> importedRealms;
+
+ FakeClassRealm(Collection<ClassLoader> importedRealms) {
+ super(new URL[0], null);
+ this.importedRealms = importedRealms;
+ }
+
+ @SuppressWarnings("unused") // called via reflection by isImportedRealm
+ public Collection<ClassLoader> getImportRealms() {
+ return importedRealms;
+ }
+ }
+}
diff --git
a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13306PackagingProviderTest.java
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13306PackagingProviderTest.java
new file mode 100644
index 0000000000..33e95d3306
--- /dev/null
+++
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13306PackagingProviderTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class MavenITgh13306PackagingProviderTest extends
AbstractMavenIntegrationTestCase {
+
+ @Test
+ void providerFromProjectExtensionIsVisibleOnlyToItsProject() throws
Exception {
+ Path testDir = extractResources("gh-13306-packaging-provider");
+
+ Verifier verifier = newVerifier(testDir.resolve("extension"));
+ verifier.setAutoclean(false);
+ verifier.deleteArtifacts("org.apache.maven.its.gh13306");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ verifier = newVerifier(testDir.resolve("client"));
+ verifier.setAutoclean(false);
+ verifier.addCliArgument("validate");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ verifier = newVerifier(testDir.resolve("reactor"));
+ verifier.setAutoclean(false);
+ verifier.addCliArgument("-T");
+ verifier.addCliArgument("2");
+ verifier.addCliArgument("validate");
+ try {
+ verifier.execute();
+ fail("The packaging provider leaked into a project without the
extension");
+ } catch (VerificationException e) {
+ assertTrue(e.getMessage().contains("Unknown packaging:
app-client"), e.getMessage());
+ assertTrue(e.getMessage().contains("without-extension"),
e.getMessage());
+ }
+ }
+}
diff --git
a/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/client/pom.xml
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/client/pom.xml
new file mode 100644
index 0000000000..4cacee9960
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/client/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its.gh13306</groupId>
+ <artifactId>client</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>app-client</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.gh13306</groupId>
+ <artifactId>packaging-extension</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/pom.xml
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/pom.xml
new file mode 100644
index 0000000000..5a8e99ff5c
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its.gh13306</groupId>
+ <artifactId>packaging-extension</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-api-core</artifactId>
+ <version>4.0.0-rc-7</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-api-di</artifactId>
+ <version>4.0.0-rc-7</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-api-spi</artifactId>
+ <version>4.0.0-rc-7</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>4.0.0-beta-1</version>
+ <extensions>true</extensions>
+ <configuration>
+ <goalPrefix>packaging</goalPrefix>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.14.0</version>
+ <configuration>
+ <release>17</release>
+ <proc>full</proc>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/src/main/java/org/apache/maven/its/gh13306/CustomPackagingProvider.java
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/src/main/java/org/apache/maven/its/gh13306/CustomPackagingProvider.java
new file mode 100644
index 0000000000..42ef85125b
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/src/main/java/org/apache/maven/its/gh13306/CustomPackagingProvider.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.its.gh13306;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.api.Packaging;
+import org.apache.maven.api.Type;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.model.PluginContainer;
+import org.apache.maven.api.spi.PackagingProvider;
+
+@Named
+public class CustomPackagingProvider implements PackagingProvider {
+
+ @Override
+ public Collection<Packaging> provides() {
+ return List.of(new CustomPackaging("app-client", new
CustomTypeProvider.CustomType(), Map.of()));
+ }
+
+ private record CustomPackaging(String id, Type type, Map<String,
PluginContainer> plugins) implements Packaging {}
+}
diff --git
a/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/src/main/java/org/apache/maven/its/gh13306/CustomTypeProvider.java
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/src/main/java/org/apache/maven/its/gh13306/CustomTypeProvider.java
new file mode 100644
index 0000000000..1b5d1d3820
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/extension/src/main/java/org/apache/maven/its/gh13306/CustomTypeProvider.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.its.gh13306;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.api.JavaPathType;
+import org.apache.maven.api.Language;
+import org.apache.maven.api.PathType;
+import org.apache.maven.api.Type;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.spi.TypeProvider;
+
+@Named
+public class CustomTypeProvider implements TypeProvider {
+
+ @Override
+ public Collection<Type> provides() {
+ return List.of(new CustomType());
+ }
+
+ static class CustomType implements Type {
+
+ @Override
+ public String id() {
+ return "app-client";
+ }
+
+ @Override
+ public Language getLanguage() {
+ return Language.JAVA_FAMILY;
+ }
+
+ @Override
+ public String getExtension() {
+ return "jar";
+ }
+
+ @Override
+ public String getClassifier() {
+ return null;
+ }
+
+ @Override
+ public boolean isIncludesDependencies() {
+ return false;
+ }
+
+ @Override
+ public Set<PathType> getPathTypes() {
+ return Set.of(JavaPathType.CLASSES);
+ }
+ }
+}
diff --git
a/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/pom.xml
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/pom.xml
new file mode 100644
index 0000000000..756251bb70
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its.gh13306</groupId>
+ <artifactId>reactor</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <modules>
+ <module>with-extension</module>
+ <module>without-extension</module>
+ </modules>
+</project>
diff --git
a/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/with-extension/pom.xml
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/with-extension/pom.xml
new file mode 100644
index 0000000000..fead60c4c7
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/with-extension/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.its.gh13306</groupId>
+ <artifactId>reactor</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>with-extension</artifactId>
+ <packaging>app-client</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.gh13306</groupId>
+ <artifactId>packaging-extension</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/without-extension/pom.xml
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/without-extension/pom.xml
new file mode 100644
index 0000000000..c7bad7e479
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13306-packaging-provider/reactor/without-extension/pom.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.its.gh13306</groupId>
+ <artifactId>reactor</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>without-extension</artifactId>
+ <packaging>app-client</packaging>
+</project>