Gradle 4.5.1 warn about it as The TaskInternal.execute() method has been deprecated and is scheduled to be removed in Gradle 5.0. There are better ways to re-use task logic, see https://docs.gradle.org/4.5.1/userguide/custom_tasks.html#sec:reusing_task_logic.
But link does not give me any hint how I could replace it because I can’t just setup task dependencies like dependsOn or finalizdBy - it called not from other task but from end of build.
By calling execute() directly, you’re by-passing all of Gradle’s task execution infrastructure.
Based on the name of the task, I assume that the task doesn’t really have any inputs/outputs and you just need it to do some work as clean-up from other things (some sort of container teardown?). There are a few alternatives you can use:
Make the tasks that rely on the “EgaisappContainer” or “EgaisdbContainer” to be finalizedBy the remove tasks. This might be faster than what you’re doing now because Gradle could run these tasks in parallel or earlier than the end of the build.
Stop using tasks and call some kind of utility-method version of these tasks to do their work. This is the closest equivalent to what you’re doing now, but it looks like a smell since you’re always doing this work unnecessarily (e.g., when someone runs gradle tasks)