# Exec task not recognized

**URL:** <https://discuss.gradle.org/t/exec-task-not-recognized/26883>\
**Category:** Help/Discuss\
**Created:** [May 10, 2018, 7:32pm UTC](https://discuss.gradle.org/t/exec-task-not-recognized/26883 "2018-05-10T19:32:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marc3](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@marc3](https://discuss.gradle.org/u/marc3)\
**Post date:** [May 10, 2018, 7:32pm UTC](https://discuss.gradle.org/t/exec-task-not-recognized/26883/1 "2018-05-10T19:32:44Z")

</div>

I am trying to run a shell script from my gradle build but it utterly fails to compile/run

```
import org.gradle.api.tasks.Exec
    ...
task generateProto(type: Exec) {
      workingDir "${projectDir}"
      commandLine = './generate_protobuf.sh'
}

build.dependsOn generateProto

```

gives me the following error

```
Could not determine the dependencies of task ':generateProto'.
> Could not find method workingDir() for arguments [...

```

According to the [latest documentation](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html) this should work. Also my IDE (IntelliJ) is marking the calls to workingDir and commandLine as not found. I am running the build from commandLine, just to be sure it is not a IDE bug.

I am on Gradle 4.7

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [May 11, 2018, 1:42am UTC](https://discuss.gradle.org/t/exec-task-not-recognized/26883/2 "2018-05-11T01:42:24Z")

</div>

Your script works as expected for me on Gradle 4.7. The only modification I made was to replace the `...` with applying the the `base` plugin so that the `build` task referenced in the last line exists. There’s not enough information here to troubleshoot.

---

<div class="post-metadata">

**Author:** ![marc3](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@marc3](https://discuss.gradle.org/u/marc3)\
**Post date:** [May 15, 2018, 6:32pm UTC](https://discuss.gradle.org/t/exec-task-not-recognized/26883/3 "2018-05-15T18:32:03Z")

</div>

Something must be off with my installation then. I’ve installed Gradle via SDKMAN.

This is my full build

```
import org.gradle.api.tasks.Exec

plugins {
  id "scala"
}

ext {
  versionScala = '2.12.5'
  versionScalaTest = '3.0.5'
  versionScalaLogging = '3.5.0'
  versionAkka = '2.5.12'
  versionLogback = '1.1.8'
  versionLevelDb = '0.10'
}

version = '0.1.0'

repositories {
  mavenCentral()
}

sourceSets.main.scala.srcDirs += 'build/generated/source/proto/main/scala'

dependencies {
  compile group: 'com.typesafe.akka', name: 'akka-http_2.12', version: '10.1.1'
  compile group: 'com.typesafe.akka', name: 'akka-stream_2.12', version: versionAkka
  compile group: 'com.typesafe.akka', name: 'akka-persistence_2.12', version: versionAkka
  compile group: 'org.fusesource.leveldbjni', name: 'leveldbjni-all', version: '1.8'
  compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.1.0'
  compile group: 'com.thesamet.scalapb', name: 'scalapb-runtime_2.12', version: '0.7.2'
  testCompile group: 'junit', name: 'junit', version: '4.+'
  testCompile group: 'org.scalatest', name: 'scalatest_2.12', version: versionScalaTest
  testCompile group: 'com.typesafe.akka', name: 'akka-testkit_2.12', version: versionAkka
  testCompile group: 'com.typesafe.akka', name: 'akka-http-testkit_2.12', version: '10.1.1'
  testCompile "org.specs2:specs2-core_2.11:4.0.3"
}

task preBuild {
  new File("build/generated/source/proto/main/scala").mkdirs()
}

task generateProto(type: Exec) dependsOn(preBuild) {
  workingDir "${projectDir}"
  commandLine = './generate_protobuf.sh'
}

build.dependsOn generateProto
```

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [May 15, 2018, 6:51pm UTC](https://discuss.gradle.org/t/exec-task-not-recognized/26883/4 "2018-05-15T18:51:04Z")

</div>

You do actually have a problem with your buildscript that wasn’t shown in the original post:

> [@marc3](#):
>
> ```groovy
> task generateProto(type: Exec) dependsOn(preBuild) {
> workingDir "${projectDir}"
> commandLine = './generate_protobuf.sh'
> }
> 
> ```

The `dependsOn(preBuild)` needs to be inside the parenthesis, using the map notation:

```groovy
task generateProto(type: Exec, dependsOn: preBuild) {
    workingDir "${projectDir}"
    commandLine = './generate_protobuf.sh'
}

```

OR inside the closure:

```groovy
task generateProto(type: Exec) {
    dependsOn(preBuild)
    workingDir "${projectDir}"
    commandLine = './generate_protobuf.sh'
}

```

---

<div class="post-metadata">

**Author:** ![marc3](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@marc3](https://discuss.gradle.org/u/marc3)\
**Post date:** [May 15, 2018, 6:57pm UTC](https://discuss.gradle.org/t/exec-task-not-recognized/26883/5 "2018-05-15T18:57:41Z")

</div>

doh!

Well, the message was kind of misleading. Thank you very much
