当前位置:网站首页>Gradle 笔记
Gradle 笔记
2022-07-02 03:00:00 【howeres】
Groovy 的闭包 (关键语法)
定义: 类似于 lambda 表达式, 传递时使用匿名内部类对象的方式
特点: 可以先声明,然后设置代理来执行
Closure closure = {
sayHello()
}
// 测试准备
class Foo {
void sayHello() {
println("Hello!!!")
}
}
def foo = new Foo()
// 开始测试, 可以看出 delegate 是一个成员变量, 而且类型是匿名的接口
closure.delegate = foo
closure()
- 调用特性:
- 可以外置 (闭包对象在最后一个参数时)
- 可以外置 + 省略括号 (仅有一个参数且为闭包时)
def running(Closure closure) {
println("start~")
closure()
println("end.")
}
running({
println("running...") })
// 闭包可以后置
running() {
println("running...")}
def caculate(Closure closure) {
def num1 = 10
def num2 = 15
closure(num1, num2)
}
caculate() {
k,v -> println("$k + $v = ${k+v}")}
// 括号可以省略, 也就是最熟悉的 Gradle 方式
caculate {
k,v -> println("$k + $v = ${k+v}") }
Gradle 的构建流程
- 生成一个
Settings对象,执行settings.gradle对这个对象进行配置 - 使用
Settings对象生成工程结构,创建Project对象 - 对所有
Project执行对应的build.gradle进行配置
脚本文件 build.gradle 的执行方式
总结一下,build.gradle 就是一个 Groovy 格式的脚本文件, 构建的时候会顺序执行, 但是打开 build.gradle 可能还是一头雾水, 一个个字符和大括号?以最长使用的 dependencies 举例
dependencies {
// This dependency is found on compile classpath of this component and consumers.
implementation 'com.google.guava:guava:26.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
同时 implementation 也可以这样写
implementation('com.google.guava:guava:26.0-jre')
implementation 其实就是函数. Groovy 中函数调用可以使用空格加参数的形式调用
void foo(String params1, int param2) {
println("param1 = $params1, param2 = $param2")
}
foo "hello", 996
Gradle 和 Groovy 的关系
Gradle 支持 Kotlin 或 Groovy 两种语言编写, 两者的关系为实现关系. Groovy 是 Gradle 的一种 DSL ( Domain Specific Language i.e., 领域专用语言)
Gradle 的 DSL 专门用于配置项目的构建不能用于其他工作. 语法还是 Groovy 自身的语法, 但调用只能依靠 Gradle 规定的 API 方式或者特定的一套规范. 强调一个 Specific 专用 (约定)
与 DSL (HTML、Makefile、LaTeX、AWK) 相对应的是可以做任何工作的通用语言 (Java 、C/C++)
边栏推荐
- QT implementation interface jump
- Common means of modeling: aggregation
- Mmsegmentation series training and reasoning their own data set (3)
- Which brand of sports headset is better? Bluetooth headset suitable for sports
- PHP notes - use Smarty to set public pages (include, if, else, variable settings)
- Actual battle of financial risk control - under Feature Engineering
- What are the common proxy servers and what are the differences?
- STM32__05—PWM控制直流电机
- Redis set command line operation (intersection, union and difference, random reading, etc.)
- Remote connection to MySQL under windows and Linux system
猜你喜欢

LeetCode刷题(十)——顺序刷题46至50

多线程查询,效率翻倍

MVVM and MVC

Soul app released the annual report on generation Z behavior: nearly 20% of young people love shopping in the vegetable market

Après le mariage
![[staff] the direction of the symbol stem and the connecting line (the symbol stem faces | the symbol stem below the third line faces upward | the symbol stem above the third line faces downward | the](/img/fe/d97b25f702bbc05f941d08147259e0.jpg)
[staff] the direction of the symbol stem and the connecting line (the symbol stem faces | the symbol stem below the third line faces upward | the symbol stem above the third line faces downward | the

LFM signal denoising, time-frequency analysis, filtering

连通块模板及变式(共4题)

2022-2028 global manual dental cleaning equipment industry research and trend analysis report

2022-2028 global encryption software industry research and trend analysis report
随机推荐
2022安全员-C证考试题及模拟考试
The number one malware in January 2022: lokibot returned to the list, and emotet returned to the top
Qualcomm platform WiFi -- Native crash caused by WiFi
es面試題
【无标题】
[learn C and fly] 3day Chapter 2 program in C language (exercise 2.3 calculate piecewise functions)
What are the common proxy servers and what are the differences?
Mathematics in Sinorgchem: computational geometry
[JS reverse series] analysis of a customs publicity platform
LFM signal denoising, time-frequency analysis, filtering
[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)
GB/T-2423.xx 环境试验文件,整理包括了最新的文件里面
JVM interview
2022-2028 global encryption software industry research and trend analysis report
Share the basic knowledge of a common Hongmeng application
Just a few simple steps - start playing wechat applet
Render header usage of El table
Which kind of sports headphones is easier to use? The most recommended sports headphones
Pat a-1165 block reversing (25 points)
Divorce for 3 years to discover the undivided joint property, or