# Add custom configuration to installDist for a specific task

**URL:** <https://discuss.gradle.org/t/add-custom-configuration-to-installdist-for-a-specific-task/38907>\
**Category:** Help/Discuss\
**Created:** [January 30, 2021, 4:13am UTC](https://discuss.gradle.org/t/add-custom-configuration-to-installdist-for-a-specific-task/38907 "2021-01-30T04:13:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mweber03](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mweber03](https://discuss.gradle.org/u/mweber03)\
**Post date:** [January 30, 2021, 4:13am UTC](https://discuss.gradle.org/t/add-custom-configuration-to-installdist-for-a-specific-task/38907/1 "2021-01-30T04:13:28Z")

</div>

I’m trying to make a custom runtime dependency configuration, so that the specified dependencies will only be installed for a specific task. The dependencies are installed using the `installDist` task. So it seems like I need the configuration to be added to the `runtimeClasspath` for one task and not the other. I’m thinking I need a custom distribution, but I’m not sure how to set that to have a different `runtimeClasspath` from the default.

In the example below, I want the `run2` task to have the `myRuntimeDep` dependencies installed, but for the `run1` task I do not.

I’ve be struggling to figure this out all day, does someone know what I’m missing?

Example `build.gradle`:

```groovy
configurations {
    myRuntimeDep.extendsFrom runtimeOnly
}

dependencies {
    ...
    myRuntimeDep 'the:dependency:1.0'
}

task run1(type: JavaExec, dependsOn: installDist) {
   // does not need myRuntimeDep dependencies
}

task run2(type: JavaExec, dependsOn: installDist) {
    // needs myRuntimeDep dependencies
}

```

---

<div class="post-metadata">

**Author:** ![mweber03](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mweber03](https://discuss.gradle.org/u/mweber03)\
**Post date:** [February 1, 2021, 5:19pm UTC](https://discuss.gradle.org/t/add-custom-configuration-to-installdist-for-a-specific-task/38907/2 "2021-02-01T17:19:38Z")

</div>

So after a long weekend, I sort of got something working. Maybe someone can tell me if there’s a better way? Also, it doesn’t fully work because it doesn’t follow transitive dependencies with the configuration (which is kind of a pain because all sub-dependencies need to be manually added).

**Solution** :  
  
  
top-level `build.gradle`

```groovy
...
subprojects {
    configurations {
        fooRuntime.extendsFrom runtimeOnly
        fooClasspath.extendsFrom runtimeClasspath, fooRuntime
    }
    
    distributions {
        foo {
            contents {
                from installDist.destinationDir
                from(configurations.fooClasspath) {
                    into 'lib'
                }
            }
        }
    }
    installFooDist.dependsOn installDist
}

```

project A `build.gradle`

```groovy
dependencies {
    fooRuntime project(':projectB')
    fooRuntime project(':projectC') // only need this because transitive dependencies won't work
}

task run(type: JavaExec, dependsOn: installFooDist) {
   classpath = fileTree("$installFooDist.destinationDir/lib")
}

```

project B `build.gradle`

```groovy
dependencies {
    fooRuntime project(':projectC')
}

task run(type: JavaExec, dependsOn: installFooDist) {
   classpath = fileTree("$installFooDist.destinationDir/lib")
}

```
