为什么在gradle中有两种创建任务的方式?

Tie*_*Nam 12 java groovy gradle

我目前正在编写一个 gradle 脚本来自动化一些构建。然而,似乎有两种创建任务的方法。我应该服用什么?为什么有不同的类型?

task copy(type: Copy, group: "Custom", description: "Copies sources to the dest directory") {
    from "src"
    into "dest"
}
Run Code Online (Sandbox Code Playgroud)

tasks.register("gutenTag", Greeting) {
    group = 'Welcome'
    description = 'Produces a German greeting'
    message = 'Guten Tag'
    recipient = 'Welt'
}
Run Code Online (Sandbox Code Playgroud)

tim*_*tes 15

第一个是将任务添加到构建的(其中一个)旧方法

第二种是使用寄存器,它可以避免任务配置

https://docs.gradle.org/current/userguide/task_configuration_avoidance.html

那是; 仅当在构建中使用该任务时才配置该任务