groovy 语言中的 gradle 任务定义是什么? [英] What are gradle task definitions in groovy language?

查看:28
本文介绍了groovy 语言中的 gradle 任务定义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 gradle 和 groovy 都是全新的,我无法找到有关下面在 groovy 语言中实际内容的信息

I'm completely new to both gradle and groovy and I'm having trouble to find information about what the below actually is in the groovy language

task myTask(dependsOn: 'compile') << {
   println 'I am not affected'
}

AFAIK {...} 部分是一个闭包,它似乎被传递给 << 之前定义的任何内容.

AFAIK the {...} part is a closure which seems to be passed to whatever is defined before <<.

task myTask() 是对构造函数的调用吗?

Is task myTask() a call to a constructor?

冒号看起来像参数的东西是什么?

And what is the thing with the colon that looks like a parameter?

<< 有什么作用?是被gradle重载的操作符还是标准的groovy?

What does << do? Is it an operator that was overloaded by gradle or is it standard groovy?

推荐答案

dependsOn: 'compile' 是一个命名参数.<< 是一个重载运算符,用于向任务添加任务操作.(有关详细信息,请参阅 Gradle 用户指南.){ ...} 是一个实现任务动作的闭包.myTask 在语法上是一个嵌套的方法调用 (task(myTask(dependsOn: 'compile') << ...)),但使用Groovy 编译器插件 (task('myTask', dependsOn: 'compile') << ...).

dependsOn: 'compile' is a named argument. << is an overloaded operator that adds a task action to the task. (See Gradle User Guide for more information.) { ... } is a closure that implements the task action. myTask is syntactically a nested method call (task(myTask(dependsOn: 'compile') << ...)), but gets rewritten to a String using a Groovy compiler plugin (task('myTask', dependsOn: 'compile') << ...).

这篇关于groovy 语言中的 gradle 任务定义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆