# Define project dependency configuration dynamically

**URL:** <https://discuss.gradle.org/t/define-project-dependency-configuration-dynamically/4905>\
**Category:** Old Forum Archive\
**Created:** [December 12, 2013, 3:22pm UTC](https://discuss.gradle.org/t/define-project-dependency-configuration-dynamically/4905 "2013-12-12T15:22:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![c2629021](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@c2629021](https://discuss.gradle.org/u/c2629021)\
**Post date:** [December 12, 2013, 3:22pm UTC](https://discuss.gradle.org/t/define-project-dependency-configuration-dynamically/4905/1 "2013-12-12T15:22:00Z")

</div>

I’ve got a subproject (let’s call it mySubProject), from which I’d like to access the archived jars of some other subprojects via a dependency configuration.

But I don’t want to define those project dependencies explicitly, but rather add them to my configuration dynamically. I’ve written some kind of loop that iterates over those project names:

```gradle
loop {
    dependencies.add("myConfigurationName", "project(path: ':$projectName', configuration: 'archives')")
}

```

But if I try to access them by something like this:

```gradle
task printConfig << {
    configurations.myConfigurationName.files.each { File file ->
        println file.name
    }
}

```

I get

“Could not find project(path: ‘:someSubprojectName’, configuration.” Required by:

src: mySubProject:0.0.0.1"

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [December 12, 2013, 7:28pm UTC](https://discuss.gradle.org/t/define-project-dependency-configuration-dynamically/4905/2 "2013-12-12T19:28:00Z")

</div>

You need to get rid of the quotes around the project dependency. A project dependency is not a String. Also, you need to change ‘project’ to ‘dependencies.project’.

---

<div class="post-metadata">

**Author:** ![c2665466](https://avatars.discourse-cdn.com/v4/letter/c/f4b2a3/32.png) [@c2665466](https://discuss.gradle.org/u/c2665466)\
**Post date:** [December 13, 2013, 9:40am UTC](https://discuss.gradle.org/t/define-project-dependency-configuration-dynamically/4905/3 "2013-12-13T09:40:00Z")

</div>

Thank you very much.

I figured, that the quotes were wrong, but I couldn’t get Gradle to evaluate the $projectName variable.

It works with

```gradle
dependencies.add("myConfigurationName", dependencies.project(path: ":$projectName", configuration: 'archives'))

```

Guess that failed before, because I just wrote “project” instead of “dependencies.project”

You can mark this one as answered.
