Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 584
Laurence Gonsalves Avatar asked Mar 23 '16 18:03

Laurence Gonsalves


1 Answers

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

like image 61
newhouse Avatar answered Sep 28 '22 03:09

newhouse