当前位置:网站首页>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++)
边栏推荐
- 3048. Number of words
- Vsocde has cli every time it is opened js
- 实现一个自定义布局的扫码功能
- [Chongqing Guangdong education] Sichuan University concise university chemistry · material structure part introductory reference materials
- [learn C and fly] 2day Chapter 8 pointer (practice 8.1 password unlocking)
- 创业了...
- Actual battle of financial risk control - under Feature Engineering
- Special symbols in SAP ui5 data binding syntax, and detailed explanation of absolute binding and relative binding concepts
- 结婚后
- [JVM] detailed description of the process of creating objects
猜你喜欢

Ten minutes will take you in-depth understanding of multithreading - multithreaded teamwork: synchronous control

MongoDB非關系型數據庫
![[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)](/img/96/8c4baa1dd8e35e2cab67461e7c447b.jpg)
[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)

Deployment practice and problem solving of dash application development environment based on jupyter Lab

How to turn off the LED light of Rog motherboard

Special symbols in SAP ui5 data binding syntax, and detailed explanation of absolute binding and relative binding concepts

2022-2028 global wood vacuum coating machine industry research and trend analysis report

Analysis of FLV packaging format

Pychart creates new projects & loads faster & fonts larger & changes appearance

buu_ re_ crackMe
随机推荐
AcWing 245. Can you answer these questions (line segment tree)
寻找重复数[抽象二分/快慢指针/二进制枚举]
Possible causes of runtime error
使用开源项目【Banner】实现轮播图效果(带小圆点)
LeetCode刷题(十)——顺序刷题46至50
Oracle creates a user with read-only permission in four simple steps
ZABBIX API creates hosts in batches according to the host information in Excel files
2022-2028 global manual dental cleaning equipment industry research and trend analysis report
Kibana controls es
自定义组件的 v-model
[liuyubobobo play with leetcode algorithm interview] [00] Course Overview
What kind of good and cost-effective Bluetooth sports headset to buy
2022-2028 global military computer industry research and trend analysis report
What is the function of the headphone driver
Stdref and stdcref
OSPF LSA message parsing (under update)
批量检测url是否存在cdn—高准确率
[Chongqing Guangdong education] Sichuan University concise university chemistry · material structure part introductory reference materials
只需简单几步 - 开始玩耍微信小程序
New programmer magazine | Li Penghui talks about open source cloud native message flow system