.gradle
• 

• 2 

• ( ) 2 

• 

• 5 🤗

• 3 , 4.5 ?
…?🤔
?
[ ] .
+
It works! 🥳
+
• 

• , , …

• API 

• 

• 

• Stackoverflow
[ ] .

• 

• 

•
android {
compileSdkVersion 28
defaultConfig {
applicationId “a.b.c”
minSdkVersion 21
targetSdkVersion 28
……

}
}
JSON? 🤔
dependencies {
implementation fileTree(dir: 'libs', include: [‘*.jar'])
}
CODE? 🤔
Gradle is an open-source build automation system that builds upon
the concepts of Apache Ant and Apache Maven and introduces
a Groovy-based domain-specific language (DSL) instead of
the XML form used by Apache Maven for declaring the project
configuration.
Gradle by wikipedia
• 

• Groovy DSL ( )
Gradle is an open-source build automation system that builds upon
the concepts of Apache Ant and Apache Maven and introduces
a Groovy-based domain-specific language (DSL) instead of
the XML form used by Apache Maven for declaring the project
configuration.
Gradle by wikipedia
by wikipedia
  

? APK!
by wikipedia
• 

•
• 

• 

DSL
• DSL     . 

• = 

• ex) Emacs Emacs Lisp

• Gradle DSL - Gradle 

• Groovy Gradle
Groovy by wikipedia
• , , 

.

• .

• - 

• Python, JavaScript, …
take coffee with sugar, milk and liquor
take(coffee).with(sugar, milk).and(liquor)
a = "a"
def b = "b"
multiply = a * b !// error!
one = 1
str = "I'm the $one"
def addAndPrint(num1, num2) {
result = num1 + num2
println(result)
}
addAndPrint 3, 5
addAndPrint(3, 5)
def sayHello(paramMap) {
first = paramMap.firstName
last = paramMap.lastName
println "Hello, $first $last"
}
sayHello lastName: " ", firstName: " "
!// hello,
• 

• 

•
1 (first-class citizens)
• 

•
fun main(args: Array<String>) {
fun twice(number: Int): Int {
return number * 2
}
val numbers = listOf(1, 2, 3, 4, 5)
val lambda = !::twice
val result = numbers.map(lambda)
println(result)
!// prints [2, 4, 6, 8, 10]
}
Example.kt
def doExecute(fun) {
fun()
}
printHello = {
println "Hello"
}
doExecute(printHello)
doExecute printHello
doExecute { println "Hello" }
• 

• 

• Closure
def printNumberAndExecute(num, fun) {
println num
fun()
}
printHello = {
println "Hello"
}
printNumberAndExecute(3, printHello)
!// result
printNumberAndExecute(3, printHello)
printNumberAndExecute 3, printHello
printNumberAndExecute 3, { println "Hello" }
printNumberAndExecute(3) { println "Hello" }
printNumberAndExecute 3 { println "Hello" }
printNumberAndExecute(3, printHello)
printNumberAndExecute 3, printHello
printNumberAndExecute 3, { println "Hello" }
printNumberAndExecute(3) { println "Hello" }
printNumberAndExecute 3 { println "Hello" }
printNumberAndExecute 3 { println "Hello" }
groovy.lang.MissingMethodException: No
signature of method: java.lang.Integer.call() is
applicable for argument types:
build.gradle
testImplementation("com.robolectric:robolectric:3.3.2") {
exclude group: 'org.apache.ant'
}
..?
• Delegate
•
def printClosure = { printText "Delegated by" }
class WriterOne {
def printText(str) { println "$str WriterOne" }
}
class WriterTwo {
def printText(str) { println "$str WriterTwo" }
}
printClosure.delegate = new WriterOne()
printClosure() !// "Delegated by WriterOne"
printClosure.delegate = new WriterTwo()
printClosure() !// "Delegated by WriterOne"
class Greet {
def name
Greet(name) { this.name = name}
}
Greet.metaClass.bye = { println "Goodbye, $name" }
greet = new Greet("KyoungJoo")
greet.bye()
build.gradle
testImplementation("com.robolectric:robolectric:3.3.2") {
exclude group: 'org.apache.ant'
}
?
..?
Delegate
android {

……

}


dependencies {

testImplementation("com.robolectric:robolectric:3.3.2") {
exclude group: 'org.apache.ant'
}
}
build.gradle
?
• Delegate

• 

• Delegate 

• 

• 

•
Delegate
Type of script Delegates to instance of
Common Script
Build script Project
Init script Gradle
Settings script Settings
include ':presentation', ':domain', ':data'
Settings.gradle
Type of script Delegates to instance of
Common Script
Build script Project
Init script Gradle
Settings script Settings
. . . . . . . . . . . . . . .
Settings API Documentation
android {

……

}


dependencies {

testImplementation("com.robolectric:robolectric:3.3.2") {
exclude group: 'org.apache.ant'
}
}
build.gradle
Build script Project
Product API Documentation
android {

……

}


dependencies {

testImplementation("com.robolectric:robolectric:3.3.2") {
exclude group: 'org.apache.ant'
}
}
build.gradle
testImplementation ?
void dependencies
(Closure configureClosure)
• Configures the dependencies for this project.

• This method executes the given closure against
the DependencyHandler for this project.
The DependencyHandler is passed to the closure
as the closure's delegate.

• Closure DependencyHandler Delegate
0/0🤔
?
• Delegate

• 

• Delegate 

• 

• 

•
plugin
android {
compileSdkVersion 28
defaultConfig {
……
}
buildTypes {
……
}
}
apply plugin: 'com.android.application'
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
android {
compileSdkVersion 28
defaultConfig {
applicationId “a.b.c”
minSdkVersion 21
targetSdkVersion 28
……

}
}
?
• Delegate

• 

• Delegate 

• 

• 

•
Gradle 

Block , 

Delegate
( ) Plugin . 

Plugin
=> Groovy Gradle !
• Groovy Groovy . 

• Gradle API Groovy Kotlin
.
Gradle.
• ProductFlavor

• BuildConfig

• 

• Apk
signingConfigs {
release {
storeFile new File(System.properties['user.home'],
teamupKeystoreProperties['RELEASE_STORE_FILE'])
storePassword teamupKeystoreProperties['RELEASE_STORE_PASSWORD']
keyAlias teamupKeystoreProperties['RELEASE_KEY_ALIAS']
keyPassword teamupKeystoreProperties['RELEASE_KEY_PASSWORD']
}
someVender {
storeFile new File(System.properties['user.home'],
someVenderKeystoreProperties['RELEASE_STORE_FILE'])
storePassword someVenderKeystoreProperties['RELEASE_STORE_PASSWORD']
keyAlias someVenderKeystoreProperties['RELEASE_KEY_ALIAS']
keyPassword someVenderKeystoreProperties['RELEASE_KEY_PASSWORD']
}
}
Groovy
• flavor keystore
)
Groovy
variant.outputs.all {
outputFileName = outputFileName.replaceFirst(".apk",
"-v${versionCode}-${Instant.now()}.apk")
}
Gradle.
• https://developer.android.com/studio/build

• Android - - - 

• 

• ( ) 

•
Gradle Kotlin DSL
• Groovy Kotlin DSL 

• IDE 

• 12 1.0 

•
repositories {
maven { setUrl("http:!//dl.bintray.com/kotlin/kotlin-eap") }
mavenCentral()
jcenter()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-
core:1.0.1")
testCompile("junit", "junit", "4.12")
}

.gradle 파일 정독해보기