# Multiple classpaths for JavaExec

**URL:** <https://discuss.gradle.org/t/multiple-classpaths-for-javaexec/37802>\
**Category:** Help/Discuss\
**Created:** [October 5, 2020, 12:31pm UTC](https://discuss.gradle.org/t/multiple-classpaths-for-javaexec/37802 "2020-10-05T12:31:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jahan01](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jahan01](https://discuss.gradle.org/u/jahan01)\
**Post date:** [October 5, 2020, 12:31pm UTC](https://discuss.gradle.org/t/multiple-classpaths-for-javaexec/37802/1 "2020-10-05T12:31:13Z")

</div>

Hello All,

I am trying to include multiple classpath for `JavaExec` task. I got it somehow working, but could understand why. So I am seeking help here to really understand what’s happening.

**build.gradle:**

```gradle
configurations {
    scalaRepl
}

dependencies {
    scalaRepl "org.scala-lang:scala-compiler:2.12.12"
}

```

1. My working JavaExec task is below:

```gradle
task repl(type:JavaExec) {
    doFirst {
        main = "scala.tools.nsc.MainGenericRunner"
        classpath {
            [
                configurations.scalaRepl,
                sourceSets.main.runtimeClasspath,
            ]
        }
        standardInput System.in
        args '-usejavacp'
    }
}

```

1. This also works:

```gradle
        ...
        classpath = configurations.scalaRepl
        classpath {
            [
                sourceSets.main.runtimeClasspath,
            ]
        }
        ...

```

1. This also works

```gradle
classpath = configurations.scalaRepl + sourceSets.main.runtimeClasspath

```

**But below `classpath` setting doesn’t work:**

1. 

```gradle
classpath = configurations.scalaRepl
classpath = sourceSets.main.runtimeClasspath

```

I’m novice to groovy/gradle so really dont know why things are working. Would be nice if someone explains what is happening and what should be the correct way to combine multiple entries into one for classpath

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [October 8, 2020, 3:34pm UTC](https://discuss.gradle.org/t/multiple-classpaths-for-javaexec/37802/2 "2020-10-08T15:34:08Z")

</div>

Firstly, you should never initialise task inputs in a `doFirst{...}` block. This closure is invoked in Gradle’s execution phase, task inputs should be configured in the configuration phase. See [build phases](https://docs.gradle.org/current/userguide/build_lifecycle.html#sec:build_phases)

Secondly you should be able to use `FileCollection.plus(FileCollection)`. Eg:

```gradle
classpath = configurations.scalaRepl.plus(sourceSets.main.runtimeClasspath)

```
