- 在B站看到一个讲解Gradle的非常棒的视频: https://www.bilibili.com/video/BV1DE411Z7nt?p=1
练习一
build.gradle
//System.out.println("hello, world!")
//println "hello world!"
//
//task("hello_world") {
// println "configure"
// doLast {
// println("Executing task")
// }
//}
afterEvaluate {
println "after evaluate"
}
task('first') {
println("configuring")
doLast { println "I'm first task"}
}
class MyAwesomePlugin implements Plugin<Project> {
@Override
void apply(Project project) {
(0..<10).each {i ->
project.task("task" + i) {
if (i % 2 == 0) {
dependsOn('first')
}
def captureI = i
doLast { println "task $captureI" }
}
}
}
}
//(0..<10).each {i ->
// task("task" + i) {
// if (i % 2 == 0) {
// dependsOn('first')
// }
// def captureI = i
// doLast { println "task $captureI" }
// }
//}
//apply ([plugin: 'java'])
//apply plugin: 'groovy'
//apply plugin: 'checkstyle'
apply plugin: MyAwesomePlugin
// gradle script plugin
//apply plugin: 'http://myserver.com/my-script'
练习二
build.gradle
import org.apache.commons.lang3.StringUtils
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
mavenCentral()
}
dependencies {
classpath group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
//implementation 'org.apache.commons:commons-lang3:3.12.0'
}
}
apply plugin: 'java'
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
mavenCentral()
}
dependencies {
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
//implementation 'org.apache.commons:commons-lang3:3.12.0'
}
if (StringUtils.isNoneEmpty("")) {}
- 这个讲师讲解的特别棒,值得反复回味
End