当前位置:网站首页>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++)
边栏推荐
- Missing numbers from 0 to n-1 (simple difficulty)
- 使用 useDeferredValue 进行异步渲染
- PMP personal sprint preparation experience
- 2022-2028 global deep sea generator controller industry research and trend analysis report
- Remote connection to MySQL under windows and Linux system
- What is the principle of bone conduction earphones and who is suitable for bone conduction earphones
- QT uses sqllite
- What is hybrid web containers for SAP ui5
- Redis set command line operation (intersection, union and difference, random reading, etc.)
- Render header usage of El table
猜你喜欢
[Chongqing Guangdong education] Sichuan University concise university chemistry · material structure part introductory reference materials
Cache processing scheme in high concurrency scenario
Leetcode question brushing (10) - sequential question brushing 46 to 50
PHP notes - use Smarty to set public pages (include, if, else, variable settings)
How to develop digital collections? How to develop your own digital collections
SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding
After marriage
MongoDB非關系型數據庫
[road of system analyst] collection of wrong topics in enterprise informatization chapter
[liuyubobobo play with leetcode algorithm interview] [00] Course Overview
随机推荐
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
Set status bar color
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
MVVM and MVC
The number one malware in January 2022: lokibot returned to the list, and emotet returned to the top
结婚后
How does proxy IP participate in the direct battle between web crawlers and anti crawlers
Actual battle of financial risk control - under Feature Engineering
Baohong industry | four basic knowledge necessary for personal finance
Soul app released the annual report on generation Z behavior: nearly 20% of young people love shopping in the vegetable market
Deployment practice and problem solving of dash application development environment based on jupyter Lab
Oracle creates a user with read-only permission in four simple steps
Design details of SAP e-commerce cloud footernavigationcomponent
浅谈线程池相关配置
SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding
[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)
New programmer magazine | Li Penghui talks about open source cloud native message flow system
What are the characteristics of common web proxy IP
Software testing learning notes - network knowledge
Addition without addition, subtraction, multiplication and division (simple difficulty)