Upgrade to Pro — share decks privately, control downloads, hide ads and more …

build.gradle.ktsの内容を モジュール間で共有化する

build.gradle.ktsの内容を モジュール間で共有化する

Takafumi Kanda

April 12, 2019
Tweet

More Decks by Takafumi Kanda

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ਆా ਸ࢙ (͔Μͩ ͔ͨ;Έ) • Twitter: @kafumi__ •

    GitHub: @kafumi • ೔࢈ࣗಈंגࣜձࣾ @ த໨ࠇ • όοΫΤϯυɾiOSɾAndroidΤϯδχΞઈࢍืूத
  2. ૝ఆ͢ΔϓϩδΣΫτ :app :featureA :featureB :data :model • τοϓϨϕϧͷΞϓϦϞδϡʔϧ • ApplicationΫϥε΍ɺDIͷઃఆͳͲΛ͢Δ

    • ػೳ͝ͱʹ෼ׂ͞ΕͨػೳϞδϡʔϧ • ͍ΘΏΔPresentation૚ͷΫϥεؚ͕·ΕΔ • σʔλI/OΛ࣮૷͢Δ • ϞδϡʔϧؒͰڞ༗͍ͨ͠σʔλΫϥεΛ
 ఆٛ͢Δ
  3. ૝ఆ͢ΔϓϩδΣΫτ :app :featureA :featureB :data :model • τοϓϨϕϧͷΞϓϦϞδϡʔϧ • ApplicationΫϥε΍ɺDIͷઃఆͳͲΛ͢Δ

    • ػೳ͝ͱʹ෼ׂ͞ΕͨػೳϞδϡʔϧ • ͍ΘΏΔPresentation૚ͷΫϥεؚ͕·ΕΔ • σʔλI/OΛ࣮૷͢Δ • ϞδϡʔϧؒͰڞ༗͍ͨ͠σʔλΫϥεΛ
 ఆٛ͢Δ
  4. ྫ: 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
  5. ྫ: 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) }
  6. ํ๏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Ϋϥεͷϝ ιουͱ࣮ͯ͠ߦ͞Ε͍ͯΔ ͷͰɺಉΫϥεͷ֦ுؔ਺ͱ ͯ͠ڞ༗෦෼Λఆٛ
  7. ํ๏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
  8. ํ๏2: Precompiled script plugin • buildSrc಺ͷ *.gradle.kts ֦ுࢠͷϑΝΠϧ͸ɺϓϥάΠ ϯͱͯ͠ίϯύΠϧ͞ΕΔ •

    ௨ৗͷ build.gradle.kts ͱಉ͡ه๏͕࢖͑Δ • plugins (ଞͷϓϥάΠϯͷ apply) ΋ఆٛͰ͖Δ • Gradle 5.3͔Β (͖ͬ͞࿩ͨ͠Α͏ͳ) ΞΫηα͕ࣗಈੜ੒ ͞ΕΔΑ͏ʹͳͬͨʂ
  9. ํ๏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