Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
build.gradle.ktsの内容を モジュール間で共有化する
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Takafumi Kanda
April 12, 2019
Technology
960
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
[JAWS-UG彩の国埼玉#12]そろそろ準備する?re:Invent2026をやさしく解説 / reinvent2026-sainokuni
sh_fk2
1
360
S3 Filesで挑む! 八戸せんべい汁の食べ頃問題
usanchuu
0
120
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
160
初海外で注意すべきこと12選!!!安全快適なre:invent生活にするために
yuuuuuuu168
1
180
ウォンテッドリーの最近のプロダクトと技術の紹介
stomk
0
200
1つのリクエストを追って理解する - llm-dのP/D分離
akhino
1
170
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
200
AI時代のPRレビューにどう向き合うか?
kairim0
1
240
CloudWatch Logsのコスト最適化:どこまでAIに任せてどこから人間が承認すべきか
yama3133
0
110
僕のハーネスを紹介します
watany
3
410
宣言型部分更新は何を解決しどこへ向かうのか
shuta13
1
490
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
7
5.1k
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Being A Developer After 40
akosma
92
590k
Designing for humans not robots
tammielis
254
26k
For a Future-Friendly Web
brad_frost
184
10k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
How to Talk to Developers About Accessibility
jct
2
580
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
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ͷ΄͏͕Αͦ͞͏