diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java
index f1290b02e574..a6db5a98139c 100644
--- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java
+++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java
@@ -252,6 +252,13 @@ protected ClassRealm setupContainerRealm(
// sisu uses realm imports to establish component visibility
extRealm.importFrom(realm, realm.getId());
}
+ // Make the container realm (maven.ext) visible from extension realms.
+ // Beans discovered in the container are sourced from maven.ext, but extension
+ // realms have plexus.core as parent and cannot reach maven.ext through the parent
+ // chain alone. Without this import, Sisu 1.1.0's FilteredBeans (enabled by
+ // jsr330ComponentVisibilityFollowsPlexusVisibility) would hide container-sourced
+ // beans when TCCL is set to an extension realm during lifecycle callbacks.
+ realm.importFrom(extRealm, extRealm.getId());
}
return extRealm;
diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12522NonExtensionPluginTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12522NonExtensionPluginTest.java
new file mode 100644
index 000000000000..d7f7bc49c357
--- /dev/null
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12522NonExtensionPluginTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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 org.junit.jupiter.api.condition.EnabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+
+/**
+ * This is a test for GH-12522.
+ *
+ * Verifies that plugins that are NOT configured with {@code
Prior to Sisu 1.1.0, {@code @Inject List
Sisu 1.1.0's {@code jsr330ComponentVisibilityFollowsPlexusVisibility} feature applies + * realm-based filtering to JSR330 bean lookups, matching the filtering already applied + * by the Plexus compatibility layer. Non-extension plugin components are no longer + * visible from the container realm.
+ * + *The reproducer uses {@code tycho-bnd-plugin} which ships a + * {@code ProjectExecutionListener} ({@code BndProjectExecutionListener}) as a + * {@code @Named} JSR330 component but is not configured as an extension in the POM.
+ */ +class MavenITgh12522NonExtensionPluginTest extends AbstractMavenIntegrationTestCase { + + /** + * Verify that a build using a plugin with JSR330 components (tycho-bnd-plugin) + * that is NOT marked as an extension completes successfully. With Sisu 1.1.0's + * realm-based JSR330 filtering, the plugin's {@code ProjectExecutionListener} + * is not visible from the container realm and should not be provisioned at all. + */ + @Test + @EnabledForJreRange(min = JRE.JAVA_21, disabledReason = "tycho-bnd-plugin 5.0.3 requires Java 21") + void testNonExtensionPluginComponentsNotPickedUp() throws Exception { + Path testDir = extractResources("gh-12522-non-extension-plugin"); + + Verifier verifier = newVerifier(testDir.toString(), "remote"); + verifier.addCliArgument("process-classes"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + } +} diff --git a/its/core-it-suite/src/test/resources/gh-12522-non-extension-plugin/pom.xml b/its/core-it-suite/src/test/resources/gh-12522-non-extension-plugin/pom.xml new file mode 100644 index 000000000000..67876ee793d0 --- /dev/null +++ b/its/core-it-suite/src/test/resources/gh-12522-non-extension-plugin/pom.xml @@ -0,0 +1,51 @@ + + +