RuntimeCapability.Builder add[Dynamic|Optional|RuntimeOnly]Requirements are deprecated because at the moment they have no practical function. The idea for them was to hold some metadata about a capability for description presentation in a ui or some kind of use by a provisioning tool. But that is a use case that hasn't been pursued yet.
What they don't do is somehow automatically wire up requirements when the capability is registered, the way requirements added via RuntimeCapability.Builder.addRequirements are wired. That's because for a dynamic cap the dynamic part of the required cap's name is not known to the kernel, and for an optional requirement whether whatever condition makes the requirement non-optional has been met is unknown to the kernel.
But it looks like there's some use of these methods where the code assumes some autowiring will happen. The problem reported in
WFCORE-3040 is an example of this.
Reproducer, starting with a near empty config a la standalone-minimalistic.xml:
The server service is not added because the op is executed post-boot, so it's capability is tracked as requiring reload. But when adding the listener, the requirement for the server is not being added (because of this bug). So, without the requirement data to tell it things are not ready (see
WFCORE-1106 for details) the kernel is not detecting the reload-required dependency and is trying to execute the stage RUNTIME steps for the listener add. These fail due to the missing dependency.