Overwrite true is removed from latest version. How could i overwrite tasks.create

Hi Team,

With 8 version below code is not working. I removed overwrite true. however getting couldnt create the taks which is not exists.

 Could not create task ':deployServiceAppEnforcementCGPAHTTPServletApp'.
   > Unnecessarily replacing a task that does not exist is not supported.  Use create() or register() directly instead.  You attempted to replace a task named 'deployServiceAppEnforcementCGPAHTTPServletApp', but there is no existing task with that name.

what is alternative way to replace tasks.create overwrite. Can you please help me on this.

allApps.each { thisApp ->
        def taskName = "generate" + thisApp.name + thisApp.apptype + "App"
        def deployTaskName = "deployServiceApp" + thisApp.name
        def thisAppBaseDir = file(GENERATED_APPS_DIR.absolutePath + "/" + thisApp.name)
        tasks.create(name: taskName, type: Class.forName("xxx.xx.xx.Generate" + thisApp.apptype + "ServiceApp"), overwrite: true) { 
            app thisApp 
        tasks.create(name: deployTaskName, dependsOn: project.tasks."${taskName}", overwrite: true) {
                                        SERVICE_TARGET = CLUSTER_NAME
                deployApp(appName: thisApp.name, appPath: GENERATED_APPS_DIR.absolutePath + File.separator + thisApp.name + File.separator + "dist" + File.separator + thisApp.name + ".war", targets: SERVICE_TARGET)
        currentTask.dependsOn deployTaskName

Overwriting existing tasks with different task instances had many bad consequences and usually isn’t necessary, hence it was removed as it usually just causes strange and hard to debug problems without much gain.

Why do you actually need to overwrite tasks?
Just make sure their tasks are unique and you can just register them without any problem and without need to attempt an overwrite.