# requireCapability with project

**URL:** <https://discuss.gradle.org/t/requirecapability-with-project/42997>\
**Category:** Help/Discuss\
**Created:** [May 25, 2022, 2:12pm UTC](https://discuss.gradle.org/t/requirecapability-with-project/42997 "2022-05-25T14:12:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ofir-popowski](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@ofir-popowski](https://discuss.gradle.org/u/ofir-popowski)\
**Post date:** [May 25, 2022, 2:12pm UTC](https://discuss.gradle.org/t/requirecapability-with-project/42997/1 "2022-05-25T14:12:33Z")

</div>

Hello

Recently I’ve been needing to use optional dependencies and found this blog post [Optional dependencies are not optional](https://blog.gradle.org/optional-dependencies)

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`

```gradle
java {
    registerFeature('feature') {
        usingSourceSet(sourceSets.main)
    }
}

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

```

And in another place I’ve added this

```gradle
dependencies {
    implementation project(":infra:cache")
    implementation(project(":infra:cache")) {
        capabilities {
            requireCapability(project(":infra:cache-feature")
        }
    }
}

```

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)

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 25, 2022, 3:03pm UTC](https://discuss.gradle.org/t/requirecapability-with-project/42997/2 "2022-05-25T15:03:46Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![ofir-popowski](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@ofir-popowski](https://discuss.gradle.org/u/ofir-popowski)\
**Post date:** [May 25, 2022, 6:08pm UTC](https://discuss.gradle.org/t/requirecapability-with-project/42997/3 "2022-05-25T18:08:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 25, 2022, 7:40pm UTC](https://discuss.gradle.org/t/requirecapability-with-project/42997/4 "2022-05-25T19:40:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris\_Dore](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/chris_dore/32/7592_2.png) [@Chris\_Dore](https://discuss.gradle.org/u/Chris_Dore)\
**Post date:** [May 26, 2022, 5:18am UTC](https://discuss.gradle.org/t/requirecapability-with-project/42997/5 "2022-05-26T05:18:20Z")

</div>

Example 6 and 7 in [Modeling feature variants and optional dependencies](https://docs.gradle.org/current/userguide/feature_variants.html#sec::consuming_feature_variants) also shows what @Vampire is describing.

---

<div class="post-metadata">

**Author:** ![ofir-popowski](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@ofir-popowski](https://discuss.gradle.org/u/ofir-popowski)\
**Post date:** [May 26, 2022, 7:04am UTC](https://discuss.gradle.org/t/requirecapability-with-project/42997/6 "2022-05-26T07:04:31Z")

</div>

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
