Laurence Gonsalves
Laurence Gonsalves

Reputation: 143154

Could not find method commandLine()

I'm attempting to add a pre-pre-build shell script to my gradle/Android-Studio build. I've added the following to app/build.gradle:

task prePreBuild << {
  commandLine 'ls'
}
preBuild.dependsOn prePreBuild

When I invoke my build with ./gradlew assembleDebug I get the following error:

Could not find method commandLine() for arguments [ls] on project ':app'

If I replace the commandLine line with something like println 'Hello' then it works fine, and I can see the output from my new task.

I searched for other mentions of "Could not find method commandLine" and found nothing. What is the correct way to invoke a shell script from this gradle task?

Upvotes: 20

Views: 11965

Answers (1)

newhouse
newhouse

Reputation: 946

You need to indicate the type of the task or use the exec block:

task execute(type: Exec) {

}

or

exec {

}

You can find more info on https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html

Upvotes: 35

Related Questions