# How best to resolve a configuration as compileClasspath does?

**URL:** <https://discuss.gradle.org/t/how-best-to-resolve-a-configuration-as-compileclasspath-does/40141>\
**Category:** Help/Discuss\
**Created:** [June 5, 2021, 1:32pm UTC](https://discuss.gradle.org/t/how-best-to-resolve-a-configuration-as-compileclasspath-does/40141 "2021-06-05T13:32:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisjr](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@chrisjr](https://discuss.gradle.org/u/chrisjr)\
**Post date:** [June 5, 2021, 1:32pm UTC](https://discuss.gradle.org/t/how-best-to-resolve-a-configuration-as-compileclasspath-does/40141/1 "2021-06-05T13:32:05Z")

</div>

Hi,

I have noticed that Gradle’s `compileClasspath` configuration does not resolve as other configurations do. In my case, I had added some `project` dependencies to the `compileOnly` configuration and observed that `compileClasspath` only contained the projects’ “API elements”. Which was fine, of course. However, when I added the _exact same_ `project` dependencies (and nothing else) to a configuration I had created myself, Gradle resolved all of their “runtime elements” instead.

After digging into the `JavaPlugin` code, I discovered that I could add the following attributes to my configuration:

```java
attribute(CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, LIBRARY))
attribute(USAGE_ATTRIBUTE, project.getObjects().named(Usage.class, JAVA_API))

```

which performed the ✨ _ **Gradle Magic** _ ✨ that I needed.

The `Category` and `Usage` classes don’t appear to be “internal” to Gradle, but is this really the **cleanest** way to create a configuration that resolves like `compileClasspath` please? I had never even heard of these classes before now, and feel like I’ve crossed some kind of threshold and entered “Dragon Territory”.

What have I done? Should I retreat, and if so, to where?

Thanks for any advice here,  
Cheers,  
Chris

---

<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:** [June 7, 2021, 4:46am UTC](https://discuss.gradle.org/t/how-best-to-resolve-a-configuration-as-compileclasspath-does/40141/2 "2021-06-07T04:46:23Z")

</div>

You are encountering Gradle’s variant aware dependency resolution.

[https://docs.gradle.org/current/userguide/variant\_model.html](https://docs.gradle.org/current/userguide/variant_model.html)

---

<div class="post-metadata">

**Author:** ![chrisjr](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@chrisjr](https://discuss.gradle.org/u/chrisjr)\
**Post date:** [June 7, 2021, 8:56am UTC](https://discuss.gradle.org/t/how-best-to-resolve-a-configuration-as-compileclasspath-does/40141/3 "2021-06-07T08:56:15Z")

</div>

Thanks for replying 👍. I suppose knowing the Dragon’s name at least means that I am doing something that is officially supported. However, I still cannot really claim to understand _precisely_ which aspects of Gradle’s functionality these attributes affect:

```java
attribute(BUNDLING_ATTRIBUTE, objects.named(Bundling.class, EXTERNAL))
attribute(CATEGORY_ATTRIBUTE, objects.named(Category.class, LIBRARY))
attribute(USAGE_ATTRIBUTE, objects.named(Usage.class, JAVA_API))

```

I suspect I may only need `USAGE_ATTRIBUTE` for my problem really. However, I think I’ll feed _ **all 3** _ princesses to the Dragon anyway, just to be safe.

Cheers,  
Chris
