Gradle: how to perform tasks performed one after another?

Basically, I have 4 tasks that I need to run sequentially, but I can not get them to do this, I have to start them one by one on the command line like this:

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

Here is 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 basically: 1. the dependsOn keyword does not work ... it is simply ignored without a log message 2. the taskname.execute()function does not work ... it is simply ignored without a log message 3. is compileReleaseJavanot recognized inside build.gradle with this specific error:Could not find property 'compileJava' on task ':drmdexsecondary:dexClasses'.

-? , . gradle... , , , gradle, , - , , , ... !

+4
2

gradle . , .

, gradle Android.

, , . . doFirst, doLast < .

gradle.

task taskX << {
    println 'taskX'
}
task taskY << {
    println 'taskY'
}
task taskZ << {
    println 'taskZ'
}
taskX.dependsOn taskY
taskY.dependsOn taskZ
taskZ.shouldRunAfter taskX
+5

, , build.gradle:

def modules = ["X", "Y", "Z", "ZZ"]

if (modules.size() > 1) {
    for(j in 1 .. modules.size()-1 ) {
        tasks[modules[j]].mustRunAfter  modules[values[j-1]]        
     }
}
+3

Source: https://habr.com/ru/post/1542110/


All Articles