0

This is my build.gradle which has three tasks (one for downloading the zip, one for unzipping it and other for executing the sh file). These tasks are dependent on each other. I am using Gradle 6. As these are dependent tasks I have used following command:

gradlew C

I get the error:

Skipping task 'B' as it has no source files and no previous output files.

build.gradle:

task A {
    description = 'Rolls out new changes'
    doLast {
        def url = "https://${serverName}/xxx/try.zip"
        def copiedZip = 'build/newdeploy/try.zip'
        logger.lifecycle("Downloading $url...")
        file('build/newdeploy').mkdirs()
        ant.get(src: url, dest: copiedZip, verbose: true)
    }
}
          
task B (type: Copy, dependsOn: 'A') {
    doLast {
        def zipFile = file('build/newdeploy/try.zip') 
        def outputDir = file("build/newdeploy")
        from zipTree(zipFile)
        into outputDir
    }
}

task C (type: Exec, dependsOn: 'B') {
    doLast {
       workingDir 'build/newdeploy/try/bin'
       executable 'sh'
       args arguments, url
       ext.output = { return standardOutput.toString() }                        
    }
}
Lukas Körfer
  • 13,515
  • 7
  • 46
  • 62
PeaceIsPearl
  • 329
  • 2
  • 6
  • 19
  • At the time your tasks `B` and `C` are executed, they are not configured, because `doLast` closures run **after** task execution. Since task `B` is not configured, it has no source files and gets skipped. – Lukas Körfer Oct 08 '20 at 14:54

1 Answers1

0

I tried following and it worked. Rather than adding a separate task to copy, added the copy function in the task A itself

task A {
    description = 'Rolls out new changes'
    doLast {
        def url = "https://${serverName}/xxx/try.zip"
        def copiedZip = 'build/newdeploy/try.zip'
        logger.lifecycle("Downloading $url...")
        file('build/newdeploy').mkdirs()
        ant.get(src: url, dest: copiedZip, verbose: true)
        def outputDir = file("build/newdeploy")
        copy {
          from zipTree(zipFile)
          into outputDir
        }
    }
}

task C (type: Exec, dependsOn: 'A') {
    doLast {
       workingDir 'build/newdeploy/try/bin'
       executable 'sh'
       args arguments, url
       ext.output = { return standardOutput.toString() }                        
    }
}
PeaceIsPearl
  • 329
  • 2
  • 6
  • 19