diff --git a/testsuite/integration/basic/pom.xml b/testsuite/integration/basic/pom.xml
index bbfae0389760..256259077de5 100644
--- a/testsuite/integration/basic/pom.xml
+++ b/testsuite/integration/basic/pom.xml
@@ -606,6 +606,11 @@
wildfly-naming-client
test
+
+ org.wildfly
+ wildfly-weld-common
+ test
+
org.wildfly.core
wildfly-cli
@@ -782,6 +787,11 @@
wildfly-core-management-subsystem
test
+
+ org.wildfly.core
+ wildfly-subsystem
+ test
+
org.wildfly.discovery
wildfly-discovery-client
@@ -816,6 +826,11 @@
jakarta.servlet.jsp-api
test
+
+ org.kohsuke.metainf-services
+ metainf-services
+ test
+
@@ -921,6 +936,32 @@
weldTest
bootableJar
+
+ create-module-cdidBcExtensionModule
+
+ jar
+
+ ${bootable-jar-maven-jar-plugin.create.modules.phase}
+
+ ${project.build.directory}/extraContent/modules/test/build-compatible-extension/main
+ ${project.build.testOutputDirectory}
+
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension.class
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCEDeploymentUnitProcessor.class
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemModel.class
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemRegistrar.class
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemRegistrar$1.class
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemRegistrar$1$1.class
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemSchema.class
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredExtension.class
+ **/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredBean.class
+ **/META-INF/services/jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension
+ **/META-INF/services/org.jboss.as.controller.Extension
+ **/META-INF/beans.xml
+
+ bce-extension
+ bootableJar
+
create-module-test-alpha
diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension.java
new file mode 100644
index 000000000000..5f5810265082
--- /dev/null
+++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright The WildFly Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;
+
+import org.jboss.as.controller.Extension;
+import org.jboss.as.controller.ModelVersion;
+import org.jboss.as.controller.OperationContext;
+import org.jboss.as.controller.OperationFailedException;
+import org.jboss.as.controller.PathElement;
+import org.jboss.as.controller.PersistentResourceXMLDescription;
+import org.jboss.as.controller.PersistentSubsystemSchema;
+import org.jboss.as.controller.ResourceDefinition;
+import org.jboss.as.controller.ResourceRegistration;
+import org.jboss.as.controller.SubsystemModel;
+import org.jboss.as.controller.SubsystemRegistration;
+import org.jboss.as.controller.SubsystemSchema;
+import org.jboss.as.controller.capability.CapabilityServiceSupport;
+import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
+import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver;
+import org.jboss.as.controller.registry.ManagementResourceRegistration;
+import org.jboss.as.controller.registry.OperationEntry;
+import org.jboss.as.controller.xml.VersionedNamespace;
+import org.jboss.as.server.AbstractDeploymentChainStep;
+import org.jboss.as.server.DeploymentProcessorTarget;
+import org.jboss.as.server.deployment.Attachments;
+import org.jboss.as.server.deployment.DeploymentPhaseContext;
+import org.jboss.as.server.deployment.DeploymentUnit;
+import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
+import org.jboss.as.server.deployment.DeploymentUnitProcessor;
+import org.jboss.as.server.deployment.Phase;
+import org.jboss.as.version.Stability;
+import org.jboss.as.weld.Capabilities;
+import org.jboss.as.weld.WeldCapability;
+import org.jboss.dmr.ModelNode;
+import org.jboss.staxmapper.IntVersion;
+import org.kohsuke.MetaInfServices;
+import org.wildfly.subsystem.SubsystemConfiguration;
+import org.wildfly.subsystem.SubsystemExtension;
+import org.wildfly.subsystem.SubsystemPersistence;
+import org.wildfly.subsystem.resource.ManagementResourceRegistrar;
+import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext;
+import org.wildfly.subsystem.resource.ResourceDescriptor;
+import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar;
+import org.wildfly.subsystem.resource.operation.ResourceOperationRuntimeHandler;
+
+@MetaInfServices(Extension.class)
+public class BCEExtension extends SubsystemExtension {
+
+ public BCEExtension() {
+ super(SubsystemConfiguration.of(BCESubsystemRegistrar.NAME, BCESubsystemModel.CURRENT,
+ BCESubsystemRegistrar::new), SubsystemPersistence.of(BCESubsystemSchema.CURRENT));
+ }
+
+ /**
+ * Model for the 'bce' subsystem.
+ */
+ public enum BCESubsystemModel implements SubsystemModel {
+ VERSION_1_0_0(1, 0, 0),
+ ;
+
+ static final BCESubsystemModel CURRENT = VERSION_1_0_0;
+
+ private final ModelVersion version;
+
+ BCESubsystemModel(int major, int minor, int micro) {
+ this.version = ModelVersion.create(major, minor, micro);
+ }
+
+ @Override
+ public ModelVersion getVersion() {
+ return this.version;
+ }
+ }
+
+ /**
+ * Schema for the 'bce' subsystem.
+ */
+ public enum BCESubsystemSchema implements PersistentSubsystemSchema {
+
+ VERSION_1_0(1, 0, Stability.DEFAULT),
+ ;
+
+ static final BCESubsystemSchema CURRENT = VERSION_1_0;
+
+ private final VersionedNamespace namespace;
+
+ BCESubsystemSchema(int major, int minor, Stability stability) {
+ this.namespace = SubsystemSchema.createSubsystemURN(BCESubsystemRegistrar.NAME, stability, new IntVersion(major, minor));
+ }
+
+ @Override
+ public VersionedNamespace getNamespace() {
+ return this.namespace;
+ }
+
+ @Override
+ public Stability getStability() {
+ return Stability.DEFAULT;
+ }
+
+ @Override
+ public PersistentResourceXMLDescription getXMLDescription() {
+ PersistentResourceXMLDescription.Factory factory = PersistentResourceXMLDescription.factory(this);
+ return factory.builder(BCESubsystemRegistrar.PATH).build();
+ }
+ }
+
+ /**
+ * Registrar for the 'bce' subsystem root resource.
+ */
+ private static final class BCESubsystemRegistrar implements SubsystemResourceDefinitionRegistrar {
+
+ static final String NAME = "bce";
+ static final PathElement PATH = SubsystemResourceDefinitionRegistrar.pathElement(NAME);
+ static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(NAME, BCESubsystemRegistrar.class);
+
+ @Override
+ public ManagementResourceRegistration register(SubsystemRegistration parent, ManagementResourceRegistrationContext context) {
+ ManagementResourceRegistration registration = parent.registerSubsystemModel(ResourceDefinition.builder(ResourceRegistration.of(PATH), RESOLVER).build());
+ ResourceDescriptor descriptor = ResourceDescriptor.builder(RESOLVER)
+ .withAddOperationRestartFlag(OperationEntry.Flag.RESTART_ALL_SERVICES)
+ .withRemoveOperationRestartFlag(OperationEntry.Flag.RESTART_ALL_SERVICES)
+ .withRuntimeHandler(new ResourceOperationRuntimeHandler() {
+ @Override
+ public void addRuntime(OperationContext context, ModelNode model) {
+ if (context.isBooting()) {
+ context.addStep(new AbstractDeploymentChainStep() {
+ @Override
+ protected void execute(DeploymentProcessorTarget processorTarget) {
+ processorTarget.addDeploymentProcessor(NAME, Phase.INSTALL, Phase.INSTALL_WELD_DEPLOYMENT, new BCEDeploymentUnitProcessor());
+
+ }
+ }, OperationContext.Stage.RUNTIME);
+ } else {
+ context.reloadRequired();
+ }
+ }
+
+ @Override
+ public void removeRuntime(OperationContext context, ModelNode model) throws OperationFailedException {
+ context.reloadRequired();
+ }
+ })
+ .build();
+ ManagementResourceRegistrar.of(descriptor).register(registration);
+ return registration;
+ }
+ }
+
+ private static final class BCEDeploymentUnitProcessor implements DeploymentUnitProcessor {
+
+ @Override
+ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
+ final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
+ try {
+ final WeldCapability weldCapability = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT)
+ .getCapabilityRuntimeAPI(Capabilities.WELD_CAPABILITY_NAME, WeldCapability.class);
+ weldCapability.registerBuildCompatibleExtension(RegisteredExtension.class, deploymentUnit);
+ } catch (CapabilityServiceSupport.NoSuchCapabilityException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+
+}
diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/DummyBean.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/DummyBean.java
new file mode 100644
index 000000000000..623ab11b6040
--- /dev/null
+++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/DummyBean.java
@@ -0,0 +1,12 @@
+/*
+ * Copyright The WildFly Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;
+
+import jakarta.enterprise.context.Dependent;
+
+@Dependent
+public class DummyBean {
+}
diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredBean.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredBean.java
new file mode 100644
index 000000000000..b9b59db56cda
--- /dev/null
+++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredBean.java
@@ -0,0 +1,10 @@
+/*
+ * Copyright The WildFly Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;
+
+// no bean defining annotation, processed via RegisteredExtension
+public class RegisteredBean {
+}
diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredExtension.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredExtension.java
new file mode 100644
index 000000000000..17b6e6d6ad33
--- /dev/null
+++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredExtension.java
@@ -0,0 +1,18 @@
+/*
+ * Copyright The WildFly Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;
+
+import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension;
+import jakarta.enterprise.inject.build.compatible.spi.Discovery;
+import jakarta.enterprise.inject.build.compatible.spi.ScannedClasses;
+
+public class RegisteredExtension implements BuildCompatibleExtension {
+
+ @Discovery
+ public void discovery(ScannedClasses sc) {
+ sc.add(RegisteredBean.class.getName());
+ }
+}
diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/SubsystemBceRegistrationTest.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/SubsystemBceRegistrationTest.java
new file mode 100644
index 000000000000..a711b0d69736
--- /dev/null
+++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/SubsystemBceRegistrationTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright The WildFly Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;
+
+import jakarta.inject.Inject;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.as.arquillian.api.ServerSetup;
+import org.jboss.as.arquillian.api.ServerSetupTask;
+import org.jboss.as.arquillian.container.ManagementClient;
+import org.jboss.as.controller.PathAddress;
+import org.jboss.as.controller.operations.common.Util;
+import org.jboss.as.test.module.util.TestModule;
+import org.jboss.as.test.shared.ServerReload;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+import java.net.URL;
+
+@RunWith(Arquillian.class)
+@ServerSetup(SubsystemBceRegistrationTest.SetupTask.class)
+public class SubsystemBceRegistrationTest {
+
+ @Deployment
+ public static WebArchive getDeployment() throws Exception {
+ return ShrinkWrap.create(WebArchive.class)
+ .addClasses(SubsystemBceRegistrationTest.class, DummyBean.class, TestModule.class, RegisteredBean.class)
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @Inject
+ DummyBean dummyBean;
+
+ @Inject
+ RegisteredBean registeredBean;
+
+ @Test
+ public void testBceRegisteredAndExecuted() {
+ // check plain WAR deployment
+ Assert.assertNotNull(dummyBean);
+
+ // verify BCE was executed; if so, RegisteredBean would now be resolvable
+ Assert.assertNotNull(registeredBean);
+ }
+
+ public static class SetupTask implements ServerSetupTask {
+ private static final String MODULE_NAME = "build-compatible-extension";
+ private static TestModule testModule;
+
+ @Override
+ public void setup(ManagementClient managementClient, String containerId) throws Exception {
+ URL url = BCEExtension.class.getResource(MODULE_NAME + "-module.xml");
+ File moduleXmlFile = new File(url.toURI());
+ testModule = new TestModule("test." + MODULE_NAME, moduleXmlFile);
+ testModule.addResource("bce-extension.jar")
+ .addClasses(BCEExtension.class, RegisteredExtension.class, RegisteredBean.class)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addAsServiceProvider(org.jboss.as.controller.Extension.class, BCEExtension.class);
+ testModule.create();
+
+ managementClient.getControllerClient().execute(Util.createAddOperation(PathAddress.pathAddress("extension", "test." + MODULE_NAME)));
+ managementClient.getControllerClient().execute(Util.createAddOperation(PathAddress.pathAddress("subsystem", "bce")));
+
+ ServerReload.executeReloadAndWaitForCompletion(managementClient);
+ }
+
+ @Override
+ public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
+
+ managementClient.getControllerClient().execute(Util.createRemoveOperation(PathAddress.pathAddress("subsystem", "bce")));
+ managementClient.getControllerClient().execute(Util.createRemoveOperation(PathAddress.pathAddress("extension", "test." + MODULE_NAME)));
+
+ testModule.remove();
+
+ ServerReload.executeReloadAndWaitForCompletion(managementClient);
+ }
+ }
+}
diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/build-compatible-extension-module.xml b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/build-compatible-extension-module.xml
new file mode 100644
index 000000000000..ed32ee059842
--- /dev/null
+++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/build-compatible-extension-module.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/testsuite/integration/basic/src/test/modules/test/build-compatible-extension/main/module.xml b/testsuite/integration/basic/src/test/modules/test/build-compatible-extension/main/module.xml
new file mode 100644
index 000000000000..3822eb68ecfe
--- /dev/null
+++ b/testsuite/integration/basic/src/test/modules/test/build-compatible-extension/main/module.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+