Migration from Gradle 4.10.x to Gradle 7.4

Hi All,

I am facing certain issues while migrating my Java project from 4.10 to latest 7.4 version of Gradle. Most challenging is regarding the compatibility of tasks.

  1. In earlier version I had code like below:
task "package" (overwrite: true, type: Copy) { ......} 

Looks like this syntax is not supported anymore and I have to use something like this:

tasks.register("package"){.......}

Question is, how do I pass the earlier two arguments ?
Any help/pointer to the documentation where I can find how to write/configure tasks in 7.4 ?

Thanks in Advance

Souvik

Overwriting already realized tasks that thus could have been used by some plugins already has been deprecated with Gradle 5 and removed with Gradle 6.

If the package task you want to replace is not realized yet, but was added using task configuration avoidance (tasks.register), then you can to a certain extent use tasks.replace, but even then I’d recommend to just not do it but seek a cleaner way to achieve what you want.

Generally the task "package"(type: Copy) syntax is still supported, but you will not benefit from task configuration avoidance as that is an eager way to add a task, so using tasks.register is indeed the recommended way now.

With tasks.register you just give the type as second argument to the method call when you are using Groovy DSL (tasks.register("package", Copy) { ... }). If you were using Kotlin DSL (I can only recommend it, especially for type-safety and amazing IDE support when using IntelliJ) you could also use a generic type argument. (tasks.register<Copy>("package") { ... }).

Any help/pointer to the documentation where I can find how to write/configure tasks in 7.4 ?

The Gradle documentation is imho a great resource. :slight_smile:

Thanks Bjorn. Will change accordingly.