[java]
 compileOnly
 runtimeOnly
 implementation
 testCompileOnly
 testRuntimeOnly
 testImplementation
[java-library]
 api
 compileOnlyApi
[war]
 providedCompile
[exclude]
 implementation(‘org.xx:xx:xx’) {
 exclude group: ‘org.xx’
 exclude module: ‘slf4j-api’ // or
 exclude group: ‘org.xx’, module: ‘slf4j-api’
 }
[transitive]
 implementation(‘org.hibernate:hibernate-core:3.6.3.Final’) {
 transitive(false) // no allow transitive
 }
[enfore]
 implementation(‘org.slf4j:slf4j-api:1.4.0!!’)
configurations.all() {
 Configuration config -> config.resolutionStrategy.faillOnVersionConflict()
 }
gradle tasks
gradle build
gradle run
gradle tasks --all
gradle dependencies
gradle properties
–max-workers --parallel --no-parallel -Dorg.gradle.logging.level=quiet
 -q/quiet -w/warn -i/info -d/debug -x/exclude-task --rerun-tasks # ignore up-to-date
 –continue # generate build report
e.g. gradle init --type pom
 e.g. gradle myTask is equal to gradle mT
new A().printA()
// equivalent
def a = new A()
invokeVirtual(a, 'printA')
// equivalent to: turn(left).then(right)
turn left then right// equivalent to: take(2.pills).of(chloroquinine).after(6.hours)
take 2.pills of chloroquinine after 6.hours// equivalent to: paint(wall).with(red, green).and(yellow)
paint wall with red, green and yellow// with named parameters too
// equivalent to: check(that: margarita).tastes(good)
check that: margarita tastes good// with closures as parameters
// equivalent to: given({}).when({}).then({})
given { } when { } then { }// equivalent to: select(all).unique().from(names)
select all unique() from names// equivalent to: take(3).cookies
// and also this: take(3).getCookies()
take 3 cookies
Closure closure = {sayHello()
}
class Foo {void sayHello() {println("hello")}
}
def foo = new Foo()
closure.delegate = foo
closure() // invoke
equivalent to internal Class
task A {}
task(map, 'B')
tasks.create('C') {}
tasks.register('D') {} // Lazy loading// use exist Type
tasks.register('myClean', Delete) { delete buildDir
}task sourcesJar(type: Jar, dependsOn: classes) {classifier = 'sources'from sourceSets.main.allSource
}task javadocJar(type: Jar, dependsOn: javadoc) {classifier = 'javadoc'from javadoc.destinationDir
}4.times {tasks.register("task$it") {doLast {println "I'm task number $it"}}
}
method: tasks.findByName / getByName / findByPath / getByPath(“:project-a”)
 addRule(“description”) { taskName -> task(taskName) { doLast { print $taskName } } }
taskName.onlyIf { !project.hasProperty(‘a’) } // return if excute
 defaultTasks ‘taskA’, ‘taskB’ // project default execute Task
jvm start and shutdown is too heavy for system, better than keep running
gradle connect daemon throught socket
Project
Task
Gradle
Gradle 初始化构建, 全局单例
Project pom.xml 模块唯一对应
Settings 项目唯一, 一般只用到 include 方法
Task 前面的有向无环图基于 Task 对象
Initialzation
 settings.gradle Gradle#settingsEvaluated
 build.gradle Gradle#projectsLoaded
 Configuration
 allprojects: Gradle#beforeProject and Project#beforeEvaluate
 subprojects: Gradle#beforeProject and Project#beforeEvaluate
 SubProjectA: Gradle#beforeProject and Project#beforeEvaluate
 EXECUTE build.gradle 配置段脚本
 SubProjectA: Gradle#afterProject and Project#afterEvaluate
 ALL READY:
 Gradle#projectsEvaluated
 Gradle#taskGraph#whenReady
 Execution
 TaskExecutionGraph#beforeTask
 EXECUTE Task Action
 TaskExecutionGraph#afterTask
 ALL EXECUTED: Gradle#buildFinish
plugins {id 'java'id 'org.springframework.boot' version '2.6.3'id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}group = 'com.xxx.xx'
version = '1.0-SNAPSHOT'repositories {mavenCentral()
}dependencies {implementation 'org.springframework.boot:spring-boot-starter-web'testImplementation 'org.springframework.boot:spring-boot-starter-test'
}tasks.named('test') {// useJUnit() for junit fouruseJUnitPlatform() // for junit jupiter
}// or
buildscript {repositories {maven { url 'https://maven.aliyun.com/repository/public' }}dependencies {classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.4.1'}
}apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'