requireCapability with project


Recently I’ve been needing to use optional dependencies and found this blog post Optional dependencies are not optional

I would like to use this to declare a capability that if activated brings another internal dependency from a different place, but I couldn’t get it to work

My internal library is :infra:cache, and it should allow using another internal library called :our-project:parent-http:http-server if using feature capability

Part of :infra:cache

java {
    registerFeature('feature') {

dependencies {
    featureImplementation project(":our-project:parent-http:http-server")

And in another place I’ve added this

dependencies {
    implementation project(":infra:cache")
    implementation(project(":infra:cache")) {
        capabilities {

I tried any combination I could think of but always end up with failing to resolve the capability
What am I doing wrong?

(We’re on gradle 6.9)

project(...) is wrong here.
The capability is just a String.
So something like requireCapability("your-group:your-artifact-feature").
You revealed too less for me to tell you the exact string.
But you can easily use the task :infra:cache:outgoingVariants to get a listing.

I was using project because it’s not a published artifact, it’s just another internal module :our-project:parent-http:http-server

That’s what I would like to be based on capability

For the dependency it is fine, but as I explained, the capability has to be the correct string.

Example 6 and 7 in Modeling feature variants and optional dependencies also shows what @Vampire is describing.

Oh, now I understand, the issue was that I should have used the exact string of the group, without a version

Thank you @Vampire, and thank you @Chris_Dore that link was the perfect example I needed