Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
build.gradle.ktsの内容を モジュール間で共有化する
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Takafumi Kanda
April 12, 2019
Technology
930
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
build.gradle.ktsの内容を モジュール間で共有化する
Takafumi Kanda
April 12, 2019
More Decks by Takafumi Kanda
See All by Takafumi Kanda
FlutterでのMaterial You対応の状況と今後の展望 / The status and plan of Flutter's Material You support
kafumi
2
5.4k
Other Decks in Technology
See All in Technology
ACE-Step-1.5で見る 音楽生成AIのしくみと“破綻だけ直す”Retake機能の開発【zennfes spring 2026 登壇資料】
personabb
1
500
Snowflakeと仲良くなる第一歩
coco_se
4
490
LLMにもCAP定理があるという話
harukasakihara
0
390
エラーバジェットのアラートのタイミングを考える.pdf
kairim0
0
150
On-behalf-of Token exchange with AgentCore Identity
hironobuiga
2
220
AIのReact習熟度を測る
uhyo
2
610
マルチアカウント環境での コーディングエージェントを使った障害調査が大変なので AIエージェントにReadOnly権限を付与してみた / ReadOnly AI Agents for Multi-Account AWS Incident Response
yamaguchitk333
2
110
自律型AIエージェントは何を破壊するのか
kojira
0
160
気づかぬうちにセキュリティ負債を生むAPIキー運用
sgwrmctk
0
160
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
160
Socrates × Looker 〜セマンティックレイヤーで進化するデータ分析エージェント〜
hanon52_
3
2.4k
アジャイルな経理と Claude Code と経営の未来
kawaguti
PRO
3
140
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
225
10k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
GitHub's CSS Performance
jonrohan
1033
470k
4 Signs Your Business is Dying
shpigford
187
22k
Code Reviewing Like a Champion
maltzj
528
40k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
330
Become a Pro
speakerdeck
PRO
31
6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Mind Mapping
helmedeiros
PRO
1
250
The Curse of the Amulet
leimatthew05
1
13k
Transcript
build.gradle.ktsͷ༰Λ ϞδϡʔϧؒͰڞ༗Խ͢Δ @kafumi
ࣗݾհ • ਆా ਸ࢙ (͔Μͩ ͔ͨ;Έ) • Twitter: @kafumi__ •
GitHub: @kafumi • ࢈ࣗಈंגࣜձࣾ @ தࠇ • όοΫΤϯυɾiOSɾAndroidΤϯδχΞઈࢍืूத
ࠓͷ • ϚϧνϞδϡʔϧϓϩδΣΫτͰ • GradleεΫϦϓτͷهड़ʹKotlin DSLΛ͍ͬͯΔ߹ʹ • GradleεΫϦϓτͷ༰ΛϞδϡʔϧؒͰͲ͏ͬͯ ڞ௨Խ͢Δ͔
αϯϓϧίʔυ • https://github.com/kafumi/android-kotlin-gradle-sample • ํ๏1: Kotlin֦ுؔΛ͏ํ๏ kotlin-extϒϥϯν • ํ๏2: precompiled
script pluginΛ͏ํ๏ precompiled-scriptϒϥϯν
ఆ͢ΔϓϩδΣΫτ :app :featureA :featureB :data :model • τοϓϨϕϧͷΞϓϦϞδϡʔϧ • ApplicationΫϥεɺDIͷઃఆͳͲΛ͢Δ
• ػೳ͝ͱʹׂ͞ΕͨػೳϞδϡʔϧ • ͍ΘΏΔPresentationͷΫϥεؚ͕·ΕΔ • σʔλI/OΛ࣮͢Δ • ϞδϡʔϧؒͰڞ༗͍ͨ͠σʔλΫϥεΛ ఆٛ͢Δ
ఆ͢ΔϓϩδΣΫτ :app :featureA :featureB :data :model • τοϓϨϕϧͷΞϓϦϞδϡʔϧ • ApplicationΫϥεɺDIͷઃఆͳͲΛ͢Δ
• ػೳ͝ͱʹׂ͞ΕͨػೳϞδϡʔϧ • ͍ΘΏΔPresentationͷΫϥεؚ͕·ΕΔ • σʔλI/OΛ࣮͢Δ • ϞδϡʔϧؒͰڞ༗͍ͨ͠σʔλΫϥεΛ ఆٛ͢Δ
buildSrcΛ͏ • buildSrc • ࣗಈతʹίϯύΠϧ͞Εͯɺશ ϞδϡʔϧͷGradleεΫϦϓτ ͷґଘઌͱͯ͠ΘΕΔ • ͭ·ΓɺbuildSrcͰఆٛͨ͠ ͷɺશϞδϡʔϧͷGradle
εΫϦϓτ͔Β͑Δ
ྫ: DependencyఆٛΛ ఆͱͯ͠ڞ௨Խ͢Δ object Versions { !// … !//
Google libraries const val appCompat = "1.0.2" const val constraintLayout = "1.1.3" const val lifecycle = "2.0.0" !// 3rd-party libraries const val timber = "4.7.1" } object Deps { !// … object AndroidX { const val appCompat = "androidx.appcompat:appcompat:${Versions.appCompat}" const val constraintLayout = "androidx.constraintlayout:constraintlayout:$ {Versions.constraintLayout}" const val lifecycle = "androidx.lifecycle:lifecycle-extensions:${Versions.lifecycle}" } !// … } buildSrc/src/main/kotlin/Dependencies.kt
ྫ: DependencyఆٛΛ ఆͱͯ͠ڞ௨Խ͢Δ dependencies { implementation(project(":featureA")) !// Kotlin implementation(Deps.Kotlin.stdlibJdk) !//
Debug utilities implementation(Deps.Debug.timber) } app/build.gradle.kts featureA/build.gradle.kts dependencies { implementation(project(":data")) implementation(project(":model")) !// Kotlin implementation(Deps.Kotlin.stdlibJdk) !// AndroidX implementation(Deps.AndroidX.appCompat) implementation(Deps.AndroidX.constraintLayout) implementation(Deps.AndroidX.lifecycle) !// Debug utilities implementation(Deps.Debug.timber) }
None
ͬͱڞ௨Խ͍ͨ͠
buildSrcΛͬͱ͏ • ํ๏1: ڞ༗෦ΛbuildSrcʹ֦ுؔͱͯ͠ఆٛ͢Δ • ํ๏2: ڞ༗෦ΛPrecompiled script pluginͱͯ͠ఆٛ͢ Δ
ํ๏1: ֦ுؔ https://inside.pixiv.blog/makun/6409
ํ๏1: ֦ுؔ fun KotlinBuildScript.applyAndroidLibrary() { androidLibrary { compileSdkVersion(Versions.compileSdk) buildToolsVersion(Versions.buildTools) defaultConfig
{ minSdkVersion(Versions.minSdk) targetSdkVersion(Versions.targetSdk) } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } buildTypes { getByName("release") { isMinifyEnabled = false consumerProguardFile(file("proguard-rules.pro")) } } libraryVariants.all { generateBuildConfigProvider!?.configure { isEnabled = false } } } buildSrc/src/main/kotlin/AndroidConfigurations.kt GradleεΫϦϓτ KotlinBuildScriptΫϥεͷϝ ιουͱ࣮ͯ͠ߦ͞Ε͍ͯΔ ͷͰɺಉΫϥεͷ֦ுؔͱ ͯ͠ڞ༗෦Λఆٛ
ํ๏1: ֦ுؔ fun KotlinBuildScript.applyAndroidLibrary() { androidLibrary { compileSdkVersion(Versions.compileSdk) buildToolsVersion(Versions.buildTools) defaultConfig
{ minSdkVersion(Versions.minSdk) targetSdkVersion(Versions.targetSdk) } compileOptions { … buildSrc/src/main/kotlin/AndroidConfigurations.kt ϓϥάΠϯ͕ఏڙ͢ΔΫϥε ͷΞΫηα͕ࣗಈੜ͞Ε ͳ͍ͷͰɺࣗͰఆٛ͢Δඞ ཁ͕͋Δ internal fun Project.android(configure: BaseAppModuleExtension.() !-> Unit): Unit = (this as ExtensionAware).extensions.configure("android", configure) internal fun Project.androidLibrary(configure: LibraryExtension.() !-> Unit): Unit = (this as ExtensionAware).extensions.configure("android", configure) internal fun Project.kotlin(configure: KotlinProjectExtension.() !-> Unit): Unit = (this as ExtensionAware).extensions.configure("kotlin", configure) buildSrc/src/main/kotlin/Accessors.kt
ڞ༗෦Λ applyAndroidLibrary() ݺͼग़͠ʹஔ͖͑ΒΕΔ
͕ࠩ͋Δͱ͜Ζ͚ͩɺ֤ϞδϡʔϧͷεΫϦϓτʹॻ͚Α͘ͳΔ
͕ࠩ͋Δͱ͜Ζ͚ͩɺ֤ϞδϡʔϧͷεΫϦϓτʹॻ͚Α͘ͳΔ plugins෦ ڞ༗ԽͰ͖ͳ͍͔
ํ๏2: Precompiled script plugin • buildSrcͷ *.gradle.kts ֦ுࢠͷϑΝΠϧɺϓϥάΠ ϯͱͯ͠ίϯύΠϧ͞ΕΔ •
௨ৗͷ build.gradle.kts ͱಉ͡ه๏͕͑Δ • plugins (ଞͷϓϥάΠϯͷ apply) ఆٛͰ͖Δ • Gradle 5.3͔Β (͖ͬͨ͞͠Α͏ͳ) ΞΫηα͕ࣗಈੜ ͞ΕΔΑ͏ʹͳͬͨʂ
ํ๏2: Precompiled script plugin import org.gradle.api.JavaVersion plugins { id("com.android.library") id("kotlin-android")
} android { compileSdkVersion(Versions.compileSdk) buildToolsVersion(Versions.buildTools) defaultConfig { minSdkVersion(Versions.minSdk) targetSdkVersion(Versions.targetSdk) } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } buildTypes { getByName("release") { isMinifyEnabled = false consumerProguardFile(file("proguard-rules.pro")) } } ↗ ʹଓ͘ ↙ ͔Βଓ͘ libraryVariants.all { generateBuildConfigProvider!?.configure { isEnabled = false } } } kotlin { sourceSets.all { languageSettings.progressiveMode = true } } buildSrc/src/main/kotlin/ android-library.gradle.kts
ڞ༗෦Λ `android-library` ϓϥάΠϯͷ apply ʹஔ͖͑ΒΕΔ
·ͱΊ • ϞδϡʔϧؒͰbuild.gradle.ktsͷ༰Λڞ௨Խ͢Δʹओ ʹ2ͭͷํ๏͕͋Δ • ํ๏1: ڞ༗෦ΛbuildSrcʹ֦ுؔͱͯ͠ఆٛ͢Δ • ํ๏2: ڞ༗෦ΛPrecompiled
script pluginͱͯ͠ఆٛ ͢Δ • Gradle 5.3Ҏ߱Ͱ͋Εɺํ๏2ͷ΄͏͕Αͦ͞͏