Hi, Can someone help me out with the alternative ...
# community-support
p
Hi, Can someone help me out with the alternative to the task execute() method. I have upgraded my SpringBoot 1.5.x application to the 2.7.18 version and also upgrade the Gradle version to 8.6. Due to which the following task is not working.
Copy code
task('zipConfig', type:Zip) {
    archiveBaseName = 'objectharvesterservice-restapi'
    archiveClassifier = 'tomcat'
    from('src/main/assemblies/tomcat/zip')
}

tasks.named('bootWar').configure {
    doLast {
        copy {
            from "build/libs/objectharvesterservice-restapi.war"
            into "src/main/assemblies/tomcat/zip/objectharvesterservice-restapi-${version}/webapps"
            rename "objectharvesterservice-restapi.war", "objectharvesterservice.war"
        }
        copy {
            from "src/main/assemblies/tomcat/conf"
            into "src/main/assemblies/tomcat/zip/objectharvesterservice-restapi-${version}/conf"
        }
        mkdir "src/main/assemblies/tomcat/zip/objectharvesterservice-restapi-${version}/temp"
        tasks['zipConfig'].execute()
    }
}
t
You could declare the zipConfig task as finalizing the bootWar task. But I'd rather refactor this code to: • avoid that
doLast
on an existing task, and instead configure the zipConfig task to do the equivalent (putting the files directly into the generated ZIP file rather than to an intermediary folder) • properly declare dependencies between tasks (use the bootWar task's outputs as inputs to the zipConfig task, rather than relying on file paths alone) • maybe declare the zipConfig as a dependency of the assemble task, rather than as a finalizer of bootWar
☝️ 1
Something like:
Copy code
task('zipConfig', type: Zip) {
  archiveBaseName = 'objectharvesterservice-restapi'
  archiveClassifier = 'tomcat'
  from(tasks.named('bootWar')) {
    into "objectharvesterservice-restapi-${version}/webapps"
    rename "objectharvesterservice-restapi.war", "objectharvesterservice.war" // this could probably be improved
  }
  from('src/main/assemblies/tomcat/conf') {
    into "objectharvesterservice-restapi-${version}/conf"
  }
}
tasks.named('assemble') { dependsOn('zipConfig') }
p
Thanks @Thomas Broyer