Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make tasks execute one after another?

Basically I have 4 tasks that I need to run sequentially, but I cannot make them do so, I have to run it one by one on the command line as so:

gradle :drmdexsecondary:compileReleaseJava --info --debug --stacktrace gradle :drmdexsecondary:dexClasses --info --debug --stacktrace gradle :drmdexsecondary:jar --info --debug --stacktrace 

Here's my build.gradle:

evaluationDependsOnChildren();      task dexClasses( type:Exec ) {          //    compileJava.execute()              String cmdExt = Os.isFamily(Os.FAMILY_WINDOWS) ? '.bat' : ''              println("${buildDir}")         println("${androidSdkDir}\\build-tools\\${buildToolsVersion}\\dx${cmdExt} --dex --output=${buildDir}\\classes\\classes.dex ${buildDir}\\classes\\release")              commandLine "cmd", "/c", "${androidSdkDir}\\build-tools\\${buildToolsVersion}\\dx${cmdExt} --dex --output=${buildDir}\\classes\\classes.dex ${buildDir}\\classes\\release"     }          task jar(type: Jar) {         from ("${buildDir}\\classes\\classes.dex")     } 

My problem is this:

  1. the dependsOn keyword doesn't work... it just get ignored without any log message
  2. taskname.execute() function doesn't work... it just get ignored without any log message
  3. compileReleaseJava is not recognized inside build.gradle with this particular error: Could not find property 'compileJava' on task ':drmdexsecondary:dexClasses'.

Would anyone please help?

I've consulted and copy paste from the documentation but none of them seems work. I've even tried to re-install Gradle... there is so few sample codes there and although I understand the concept, it seems so difficult to translate my intention into working Gradle code, so if there is any good resources to help, it will be very appreciated as well.

like image 587
Zennichimaro Avatar asked May 27 '14 03:05

Zennichimaro


People also ask

How do I run a task after another task in gradle?

you should use dependsOn key wordsand then move apk File to my Project/apkFile folder . and execute success. Show activity on this post. You can create a task of type GradleBuild and define the tasks inside of that task.

Can task call another task?

Task declaration is declarative not imperative. So a task can depend on another task but they cannot execute another task.


1 Answers

You should read about gradle tasks and more about tasks. You want to depend on things rather then invoke things.

Also I think you should read about, and use the gradle android plugin.

To your original question, when you define a task the code between the braces is run at configuration time. A task's actions are run when the task is executed and must be added to the task's action list. This is done by using the task's doFirst, doLast or the << operator.

Here is an example from the gradle documentation.

task taskX << {     println 'taskX' } task taskY << {     println 'taskY' } task taskZ << {     println 'taskZ' } taskX.dependsOn taskY taskY.dependsOn taskZ taskZ.shouldRunAfter taskX 
like image 150
ditkin Avatar answered Oct 03 '22 02:10

ditkin