안드로이드 앱의 빌드 툴인 Gradle은 빌드 스크립트로 Groovy DSL을 사용합니다. DSL은 큰 학습 없이 사용할 수 있다는 장점이 있지만, 각 구문의 역할이나 의미를 정확히 알기는 어렵습니다. 이에 대한 기본적인 이해가 생긴다면, 직접 코드를 추가하거나 기존 기능을 개선시키는 등 적극적으로 빌드 과정을 조절하는데 도움이 될 것입니다. 이 세션에서는 Groovy 문법을 간단하게 소개하고, Gradle 파일들을 구문별로 의미하는 바를 짚어보며 gradle 파일을 읽는 법을 알아봅니다. 그리고 원하는 기능을 찾기 위해서 어떤 레퍼런스를 찾아야 하는지에 대한 팁을 공유합니다.
10. 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
11. •
• 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
21. •
•
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
26. printNumberAndExecute 3 { println "Hello" }
groovy.lang.MissingMethodException: No
signature of method: java.lang.Integer.call() is
applicable for argument types:
34. Delegate
Type of script Delegates to instance of
Common Script
Build script Project
Init script Gradle
Settings script Settings
35. include ':presentation', ':domain', ':data'
Settings.gradle
Type of script Delegates to instance of
Common Script
Build script Project
Init script Gradle
Settings script Settings
40. 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