# Custom configuration and resolving only compile dependencies

**URL:** <https://discuss.gradle.org/t/custom-configuration-and-resolving-only-compile-dependencies/38891>\
**Category:** Help/Discuss\
**Created:** [January 28, 2021, 3:53pm UTC](https://discuss.gradle.org/t/custom-configuration-and-resolving-only-compile-dependencies/38891 "2021-01-28T15:53:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BigMichi1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bigmichi1/32/9069_2.png) [@BigMichi1](https://discuss.gradle.org/u/BigMichi1)\
**Post date:** [January 28, 2021, 3:53pm UTC](https://discuss.gradle.org/t/custom-configuration-and-resolving-only-compile-dependencies/38891/1 "2021-01-28T15:53:45Z")

</div>

i’m currently writing a small plugin but i’m stuck when i want to get a list of all dependencies that are used.

what i’m doing  
inside the plugin i create a new configuration

```gradle
def config = project.configurations.create(sourceSet.getTaskName('foo', 'bar'))

```

in the `build.gradle` that uses the plugin i add some dependencies to this configuration

```gradle
dependencies {
  fooTestBar(project(':module'))
}

```

and in `module/build.gradle` i have

```gradle
plugins {
  id 'java-library'
}
dependencies {
  implementation('org.apache.commons:commons-collections4:4.4')
  api('org.springframework:spring-context:5.2.11.RELEASE')
}

```

when i now do the following in the plugin

```gradle
List<ResolvedArtifact> = config.resolvedConfiguration.firstLevelModuleDependencies.allModuleArtifacts.flatten()

```

i get the artifacts from both declarations in `:module`, but what i’m interested in is only the api dependency, means the one that is also used when compiling the project

it looks like the entire configurations is treated as a `runtime` configuration, so i have all artifacts including the transitive ones from both declarations, instead of only the api one including the transitive ones from api

until now i was not able to find any way to see if a resolved dependency / artifact is of type api which i do not want to have in my result list

---

<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:** [February 1, 2021, 6:24am UTC](https://discuss.gradle.org/t/custom-configuration-and-resolving-only-compile-dependencies/38891/2 "2021-02-01T06:24:16Z")

</div>

Attributes are used to drive the variant aware dependency resolution.  
[https://docs.gradle.org/current/userguide/variant\_model.html](https://docs.gradle.org/current/userguide/variant_model.html)  
[https://docs.gradle.org/current/userguide/variant\_attributes.html](https://docs.gradle.org/current/userguide/variant_attributes.html)

At the very least you need to define `org.gradle.usage=JAVA_API` to get what you want.

```
// optional; you can also describe the intended usage of your configuration
config.canBeConsumed = false 
config.canBeResolved = true
config.attributes {
    attribute( Usage.USAGE_ATTRIBUTE, objects.named( Usage, Usage.JAVA_API ) )
}
```
