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

Let's migrate to build.gradle.kts

Let's migrate to build.gradle.kts

A step-by-step guide of how to migrate to Gradle Kotlin DSL a.k.a. build.gradle.kts in a reproducutive way.

Video available at https://youtu.be/_s-0MbA5Gvw

Presented at DroidKaigi 2019 at Bellesalle Shinjuku Grand Conference Center
https://droidkaigi.jp/2019/en/timetable/70863

Yuki Fujisaki

February 08, 2019
Tweet

More Decks by Yuki Fujisaki

Other Decks in Programming

Transcript

  1. CVJMEHSBEMFLUTʹҠߦ͠Α͏
    !UOK
    :VLJ'VKJTBLJ %FQMPZ(BUF*OD
    %SPJE,BJHJ %BZ 3PPN

    View full-size slide

  2. ର৅
    build.gradleΛ,PUMJOԽͯ͠Έ͍ͨ
    (SBEMF (SPPWZ
    ͸ͳΜͱͳ͘ॻ͍͍ͯΔ
    ,PUMJOͩͬͨΒॻ͚ͦ͏

    View full-size slide

  3. ͜ͷ෼ͷΰʔϧ
    ,PUMJOԽͷϝϦοτΛ஌Δ
    build.gradle.ktsʹҠߦ͢Δ࠶ݱՄೳͳखॱΛ஌Δ
    Α͋͘Δ໰୊ͱରԠࡦΛ஌Δ
    ࿩͞ͳ͍͜ͱ
    ߴ଎Խʢߏ੒ճආ"1*ͳͲʣ΍ϦϑΝΫλϦϯά

    View full-size slide

  4. ΞδΣϯμ
    (SBEMF,PUMJO%4-ʹ͍ͭͯ
    ,PUMJOԽͰخ͍͜͠ͱ
    ࣮ࡍͷҠߦ
    جૅฤ
    ࣮ફฤ

    View full-size slide

  5. ؀ڥ
    "OESPJE4UVEJP
    "OESPJE(SBEMF1MVHJO
    (SBEMF (SBEMF,PUMJO%4-3$

    ݱ࣌఺Ͱ࠷৽͸3$ (SBEMF,PUMJO%4-

    ࢖ͬͯΔϓϥάΠϯ͕(SBEMFܥରԠͯ͠Ε͹࠷৽͕Φεεϝ
    ࡢ೔
    ϦϦʔε

    View full-size slide

  6. (SBEMF,PUMJO%4-ʹ͍ͭͯ
    (SBEMFͰϦϦʔε

    (SBEMFϏϧυεΫϦϓτΛ,PUMJOεΫϦϓτ LUT
    Ͱॻ͚Δ
    (SBEMFຊମػೳͷҰ෦ͱͯ͠ఏڙ͞ΕΔ
    ,PUMJOεΫϦϓτͷίϯύΠϥࣗମ΋ຒΊࠐΈ
    (SPPWZ͕%FQSFDBUFEʹͳΔ༧ఆ͸ͳ͍

    View full-size slide

  7. ,PUMJOʹͳͬͯخ͍͜͠ͱ
    %FWFMPQFS&YQFSJFODF͕ߴ͍
    ίʔυิ׬͕ޮ͘ɺΤϥʔݕ͕ࠪಇ͍ͯ͘ΕΔ
    ॻ͍ͯΔίʔυͷϑΟʔυόοΫ͕ߴ଎
    ϝϯς͠΍͍͢
    ܕ͕͋ΔɺϦϑΝΫλ͕Ͱ͖Δ

    View full-size slide

  8. ͭ·Γ*%&͕ͪΌΜͱ࢓ࣄ͢Δ

    View full-size slide

  9. ઓུ
    ४උ·ͣ଍৔Λ੔͑Δ
    "(1ରԠ
    (SPPWZͷ··Ұ୴εΫϦϓτΛ੔ཧ
    ҠߦϏϧυ͕௨Δঢ়ଶΛҡ࣋͠ͳ͕ΒҠߦ
    શ෦ΛҰ౓ʹ΍Βͳ͍(SPPWZͱ,PUMJOڞଘՄ

    View full-size slide

  10. جૅฤ
    Š·ͣϓϨʔϯͳϓϩδΣΫτͰ੒ޭମݧΛੵΉ

    View full-size slide

  11. ର৅
    "OESPJE4UVEJPͰ#BTJD"DUJWJUZϓϩδΣΫτ
    σϑΥϧτઃఆ -BOHVBHF,PUMJO
    ͷ··࡞Δ

    View full-size slide

  12. ͭͷ(SBEMFεΫϦϓτ
    "OESPJE(SBEMF1MVHJOΛ࢖ͬ
    ͨΫϦʔϯͳϓϩδΣΫτ
    ·ͣ͸Ϗϧυ͕௨ΓɺΞϓϦΛ
    ىಈͰ͖Δ͜ͱΛ֬ೝ

    View full-size slide

  13. ༨ஊ
    6TF"OESPJE9BSUJGBDUTΛ༗ޮʹͯ͠ΔͱΞϓϦ͕ଈࢮ͠·͢
    // ͍͕ͭ͜൜ਓɺ1.1.3ʹ্͛·͠ΐ͏
    implementation "androidx.constraintlayout:constraintlayout:1.1.2"

    View full-size slide

  14. ॻ͖׵͑ͯΈΑ͏
    ⾣TFUUJOHTHSBEMF


    CVJMEHSBEMF


    BQQCVJMEHSBEMF

    View full-size slide

  15. TFUUJOHTHSBEMF͸ߦ
    include ':app'
    จࣈྻϦςϥϧ(SPPWZ͸'ͱ"ͷ྆ํɺ,PUMJO͸"ͷΈ
    ϝιουݺͼग़͠(SPPWZ͸()ΛলུՄɺ,PUMJOͰ͸ඞਢ
    ‎"..."ʹͯ͠()Λ෇͚Ε͹ͲͪΒͰ΋ಈ͘

    View full-size slide

  16. (SPPWZͷ··

    ฤूͨ͠ΒҰ୴ Sync ͠·͢

    View full-size slide

  17. 4ZODͷํ๏
    ώϯτతʹग़ͯ͘Δ4ZOD/PXϦϯΫ

    View full-size slide

  18. 4ZODͷํ๏
    πʔϧόʔͷ4ZOD1SPKFDUXJUI(SBEMF'JMFT
    ͜ͷϘλϯΛ͓͖֮͑ͯ·͠ΐ͏

    View full-size slide

  19. ௨ͬͨΒɺϑΝΠϧ໊Λมߋͯ͠ΈΔ
    1SPKFDUπϦʔ͔Βsettings.gradleΛϦωʔϜ 4IJGU'

    build.gradle.ktsʹม͑·͢
    Ҿ਺໊ώϯτ͕ग़͖ͯͯಥવ*%&ͷཧղ౓͕͏ͳ͗ొΓ

    View full-size slide

  20. ࢼ͠ʹଘࡏ͠ͳ͍ࣝผࢠΛॻ͍ͯΈΔ
    (SPPWZWT,PUMJO
    ੺͘ͳΔʂؒҧͬͯΔ͜ͱΛͦͷ৔Ͱࢦఠͯ͘͠ΕΔ
    τϥΠΞϯυΤϥʔ͕ര଎Խ

    View full-size slide

  21. ॻ͖׵͍͑ͯ͘


    TFUUJOHTHSBEMF
    ⾣CVJMEHSBEMF


    BQQCVJMEHSBEMF

    View full-size slide

  22. ϓϩδΣΫτϧʔτͷbuild.gradle

    View full-size slide

  23. ػցతͳमਖ਼ ਖ਼نදݱνʔτγʔτ

    จࣈྻϦςϥϧ'([^']+)'‎"$1"
    ϝιουݺͼग़͠(classpath|delete) (\S+)‎$1($2)

    View full-size slide

  24. 4ZOD௨ͬͨΒϑΝΠϧ໊Λมߋ
    1SPKFDUπϦʔ͔Β1SPKFDUͷbuild.gradleΛϦωʔϜ

    View full-size slide

  25. ౖΒΕΔ
    ͦ͏қʑͱ,PUMJOͩͱ͸ೝΊͯ͘Εͳ͍
    ͕ɺϦωʔϜ࣌఺Ͱ͸Կ͕ѱ͍ͷ͔ڭ͑ͯ͘ͳ͍

    View full-size slide

  26. ΤϥʔΛ஌Δ
    4ZOD͢ΔͱίϯιʔϧʹΤϥʔ͕ग़Δ
    Ұ౓ґଘؔ܎ΛධՁͰ͖Δ·Ͱίʔυʹ৭͕෇͔ͳ͍

    View full-size slide

  27. ࠷ॳͷนext
    buildscript {
    ext.kotlin_version = "1.3.20" // => Unresolved reference: ext
    }
    extͳΜͯఆٛ͞Εͯͳ͍ͧͱݴΘΕΔ

    View full-size slide

  28. ͦ΋ͦ΋extͬͯ
    ΞυϗοΫʹ޷͖ͳ஋ΛಥͬࠐΊΔ,FZ7BMVF4UPSF
    Project ˺build.gradle
    ͕ࣗಈతʹ͍࣋ͬͯΔ
    extʹηοτͨ͠ޙ͸ProjectͷείʔϓͰ΋ࢀরՄೳ
    rootProjectͰηοτͨ͠஋͸͢΂ͯͷࢠProject͔Β
    ΋ݟ͑Δ
    ࣮ߦॱংͷؔ܎্buildscript {}಺Ͱఆٛ͢Δඞཁ͕͋Δ

    View full-size slide

  29. ಁաੑ
    buildscript {
    ext.kotlin_version = "1.3.20"
    }
    // ext είʔϓͰ΋ɺ Project είʔϓͰ΋ࢀরͰ͖Δ
    println ext.kotlin_version // => "1.3.20"
    println kotlin_version // => "1.3.20"
    SPPU1SPKFDUͰఆٛͨ͠஋͸ଞͷ1SPKFDU͔Β΋ࢀরͰ͖Δ
    // app/build.gradle
    println kotlin_version // => "1.3.20"
    println rootProject.kotlin_version // => "1.3.20"

    View full-size slide

  30. Ұํ,PUMJO͸੩తܕ෇͚ݴޠ
    ͍͖ͳΓ୅ೖ͠Α͏ͱͯ͠΋ະఆٛͷϓϩύςΟͱݟ၏͞ΕΔ

    View full-size slide

  31. ٹੈओextra
    ExtraPropertiesExtensionsͰఏڙ͞ΕΔҕৡϓϩύςΟ
    ม਺ͱͯ͠ࢀরͭͭ͠ɺ಺෦Ͱext΁ͷTFUHFUΛҕৡ
    ܕਪ࿦͕ޮ͘

    View full-size slide

  32. ͜͜Λॻ͖׵͑Δ͚ͩͰੈքʹ৭͕ʂ

    View full-size slide

  33. ࣍ͷนtasksͷमਖ਼
    taskͷఆٛͷߏจมߋ
    // Groovy
    task clean(type: Delete) {}
    ɹɹɹɹɹɹ‑
    // Kotlin
    tasks.create("clean", type = Delete::class) {}
    // or
    task("clean") {}

    View full-size slide

  34. #&'03&CVJMEHSBEMF

    View full-size slide

  35. "'5&3CVJMEHSBEMFLUT
    !

    View full-size slide

  36. ॻ͖׵͍͑ͯ͘


    TFUUJOHTHSBEMF


    CVJMEHSBEMF
    ⾣BQQCVJMEHSBEMF

    View full-size slide

  37. BQQCVJMEHSBEMF

    View full-size slide

  38. ಉ͡Α͏ʹԼ͝͠Β͑
    จࣈྻ
    '([^']+)'ˠ"$1"
    ϝιουݺͼग़͠
    ()Λ෇͚͍ͨɺΜ͚ͩͲʜ

    View full-size slide

  39. ͜Ε͸୅ೖ ϝιουݺͼग़͠
    applicationId "sh.nothing.myapplication"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    ϝιουݺͼग़͠ͷ()ΛলུͰ͖Δ
    ϓϩύςΟ୅ೖͷ=ΛলུͰ͖Δ
    ‎ݟͨ໨ͷ۠ผ͕෇͔ͳ͍ʂ

    View full-size slide

  40. ެࣜҠߦΨΠυͷઓུ
    ʮ໎ͬͨΒҰ୴୅ೖʹͯ͠ɺౖΒΕͨΒݺͼग़͠ʹ͢΂͠ʯ

    View full-size slide

  41. ΋͘͠͸*%&ͷྗʹཔΔ
    ϝιουͩͬͨΒ$PNNBOE΋͘͠͸$USMΛԡ͠ͳ͕Β
    Ϛ΢εΧʔιϧΛ߹ΘͤΔͱఆ͕ٛҾ͚Δ
    ͜ͷ৔߹͸setMinifyEnabled(false)

    View full-size slide

  42. νʔτγʔτ
    (\w+(?:ion|Files)) (.+)$‎$1($2)
    ϓϩδΣΫτॳظઃఆͷ··Ͱ͋Ε͹͜ΕͰย෇͖·͢

    View full-size slide

  43. ௥ՃͷԼ͝͠Β͑
    จࣈྻͱϝιουݺͼग़͠ʹՃ͑ͯ
    apply plugin:ʹ΋खΛೖΕ͓͖͍ͯͨ

    View full-size slide

  44. apply plugin:͔Βplugins {}ʹҠߦ
    // apply plugin: ܈Λ
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    ɹɹɹɹɹɹ‑
    // plugins ߏจʹॻ͖׵͑Δ
    plugins {
    id("com.android.application")
    id("kotlin-android")
    id("kotlin-android-extensions")
    }

    View full-size slide

  45. plugins {}Ҡߦͷഎܠ
    (SBEMFϓϥάΠϯ͸ίʔυͰ࣮ߦ࣌ʹ௥Ճ͞ΕΔ࢓૊Έ
    ྫ"OESPJE(SBEMF1MVHJOͷandroid {}ϒϩοΫ
    project.extensions.add('android', BaseAppModuleExtension)
    ‎2Ͳ͏΍ͬͯ͜ΕΛ੩తʹղܾ͢Δͷ͔

    View full-size slide

  46. "ΞΫηα͕ੜ੒͞ΕΔ
    ,PUMJO%4-͕&YUFOTJPO͔Β,PUMJOίʔυΛࣗಈੜ੒
    ͨͩ͠QMVHJOTͰఆٛ͞Εͨ΋ͷ͚ͩ
    ͳ͓(SBEMF͸ݩʑ(SPPWZͰ΋plugins {}Λਪ঑͍ͯ͠Δ

    View full-size slide

  47. 4ZOD௨ͬͨΒϑΝΠϧ໊Λมߋ
    1SPKFDUπϦʔ͔Β.PEVMFBQQͷbuild.gradleΛϦωʔϜ

    View full-size slide

  48. 4ZODͯ͠ΤϥʔΛ֬ೝ
    ্͔Βॱʹ౗͍ͯ͘͠
    ͨ͘͞Μग़Δ͚Ͳɺͭ౗ͤ͹ෳ਺ݮΓ·͢
    ࠓճͷ৔߹͸࣮࣭ͭ

    View full-size slide

  49. MapͷҾ਺
    fileTree(dir: "libs", include: ["*.jar"])
    ࢖ͬͯͳ͍ͷͰҰ୴ίϝϯτΞ΢τͰ΋Αͦ͞͏
    ,PUMJOԽ
    fileTree("dir" to "libs", "include" to listOf("*.jar"))

    View full-size slide

  50. buildTypes {}ͷఆٛ
    release‎getByName("release")ʹ
    ΋͠not foundͱݴΘΕͨΒɺcreate("release")ʹ
    ͪΐͬͱ໘౗͍͘͞

    View full-size slide

  51. kotlin_version
    ͖ͬ͞΍Γ·ͨ͠ͶrootProjectͷext͸ʜ
    // ͢΂ͯͷ Project είʔϓͰݟ͑Δ
    val kotlin_version: String by project
    // ΋͘͠͸ `rootProject.extra` ͔Βऔಘͯ͠΋͍͍Ͱ͢
    val kotlin_version: String by rootProject.extra

    View full-size slide

  52. ͜ΕͰLUTԽ׬ྃ
    !

    View full-size slide

  53. جૅฤͷ࿩
    ॱংTFUUJOHTHSBEMFˠCVJMEHSBEMFˠBQQCVJMEHSBEMF
    (SPPWZͷ··ઌʹԼ͝͠Β͑
    จࣈྻΫΦʔτɺϝιουݺͼग़͠ɺplugins
    (SBEMFͷ֓೦ͱ(SPPWZͷ,PUMJOԽ
    extͱextra taskͷఆٛ getByNameͱcreate

    View full-size slide

  54. جૅฤͷײ૝
    ׂͱ୯७ͳஔ͖׵͕͑ଟ͍ײ͡
    ࢥͬͯͨΑΓ͸ɺ͍͚ͦ͏ͳײ͡ʁ
    ૣ଎ɺࣗ෼ͷϓϩδΣΫτͰࢼͯ͠ΈΑ͏

    View full-size slide

  55. ࣮ફฤ
    Š࣮ࡍͷϓϩδΣΫτʹಋೖ͢Δ৔߹ͷোนͱରԠࡦͷ঺հ

    View full-size slide

  56. ࢼͯ͠ΈΑ͏ͱࢥͬͨɺΜ͚ͩͲͶ

    View full-size slide

  57. ͍͍ͩͨ͜͜ͰఘΊΔ
    ಀ͍͛ͨ
    .gradleϑΝΠϧͬͯؾ͕ͭ͘ͱ૿͑ͯΔΑͶ
    Ͱ΋ʂ࣮ࡍͷҠߦͷྲྀΕ͸جૅฤͱ·ͬͨ͘ಉ͡
    ‎࣮ફฤ్தͷোนͱͯ͋͠Γ͕ͪͳ՝୊ΛऔΓ্͛ͯ঺հ

    View full-size slide

  58. ࣮ફฤτϐοΫ
    "OESPJE(SBEMF1MVHJOʹ্͛Δ
    ڊେextΛͳΜͱ͔͍ͨ͠
    ࣮͸,PUMJOεΫϦϓτ͔Β(SPPWZεΫϦϓτΛݺ΂Δ
    ϑΝΠϧͷ຤ඌʹapply plugin:͕͋Δ
    ͜ͷهड़ಈ͔ͳ͍ɺͲ͏͢Ε͹

    View full-size slide

  59. ࣮ફฤτϐοΫ
    "OESPJE(SBEMF1MVHJOʹ্͛Δ
    ڊେextΛͳΜͱ͔͍ͨ͠
    ࣮͸,PUMJOεΫϦϓτ͔Β(SPPWZεΫϦϓτΛݺ΂Δ
    ϑΝΠϧͷ຤ඌʹapply plugin:͕͋Δ
    ͜ͷهड़ಈ͔ͳ͍ɺͲ͏͢Ε͹

    View full-size slide

  60. "(1Λʹ্͛Δ
    3.3.1ʹͯ͠4ZOD

    View full-size slide

  61. (SBEMF΋্͛ͯͶͱݴΘΕΔ
    (SBEMFҎ্͕ඞཁ
    Fix Gradle wrapper and re-import project͢Δ

    View full-size slide

  62. ͜͜ͰϏϧυ͕௨Βͳ͘ͳΔ৔߹
    جຊ͸֤छϓϥάΠϯͷόʔδϣϯΛ্͛ͯղܾ
    ./gradlew --stacktrace͋ͨΓ͕ࢀߟʹͳΔ͸ͣ

    View full-size slide

  63. ࣌఺ͰͷҾ͔͔ͬΓϙΠϯτ
    google-servicesҎ্͕ඞਢ
    Ϗϧυ͸௨ͬͯ΋ΞϓϦ͕མͪͨΓɺ'BCSJD͕͏·͘ಈ͔ͳ
    ͔ͬͨΓ͢Δ
    android-junit5jacoco-android
    લऀ͕࠷৽ͷ1.3.2.0ͩͱಈ͔ͳ͍ɺ1.3.1.0ͳΒେৎ෉
    *TTVF

    View full-size slide

  64. 8"3/*/(͕ফ͑ͳ͍
    ઃఆ͕ѱ͍Α͏ʹݟ͑Δ͚Ͳɺର৅͸ϓϥάΠϯͷ࣮૷
    ϓϥάΠϯ։ൃऀͷΈΜͳ"(1ରԠͯ͘͠ΕཔΉ
    ׬શͳΔϒʔϝϥϯ

    View full-size slide

  65. "(1ʹ্͕ͬͨΒ
    settings.gradle͔ΒҠߦ͠͸͡ΊͯΈ·͠ΐ͏
    جຊฤͱಉ͡Ͱॠࡴ
    include ['"]([^'"]+)['"]ˠinclude("$1")

    View full-size slide

  66. ࣮ફฤτϐοΫ
    "OESPJE(SBEMF1MVHJOʹ্͛Δ
    ڊେextΛͳΜͱ͔͍ͨ͠
    ࣮͸,PUMJOεΫϦϓτ͔Β(SPPWZεΫϦϓτΛݺ΂Δ
    ϑΝΠϧͷ຤ඌʹapply plugin:͕͋Δ
    ͜ͷهड़ಈ͔ͳ͍ɺͲ͏͢Ε͹

    View full-size slide

  67. ڊେextΛͳΜͱ͔͍ͨ͠

    View full-size slide

  68. extͷ··ͩͱׂͱਏ͍
    ࢀর͕໘౗͍͘͞ val by extra࿈ൃ͠ΜͲ͍ΑͶ

    (SPPWZͷ··࢖ͬͯͯ΋ׂͱෆศ ίʔυδϟϯϓͰ͖ͳ͍

    View full-size slide

  69. ެࣜͷΦεεϝCVJME4SDʹ੾Γग़
    ͠·͠ΐ͏
    CVJME4SDσΟϨΫτϦ
    ϏϧυεΫϦϓτ༻ͷಛผͳϓ
    ϩδΣΫτ
    தʹஔ͍ͨεΫϦϓτ͸ɺશͯ
    ͷ1SPKFDU͔ΒࢀরՄೳ
    ֤छఆ਺΍ࣗ࡞ͷϓϥάΠϯஔ
    ͖৔ʹ࠷ద

    View full-size slide

  70. CVJME4SDࣄ࢝Ί
    σΟϨΫτϦΛ࡞Δ
    buildSrc/
    ࠷௿ݶͷϑΝΠϧΛ࡞੒
    buildSrc/settings.gradle.kts த਎͸ۭ

    buildSrc/build.gradle.kts

    View full-size slide

  71. CVJME4SDCVJMEHSBEMFLUT
    // kotlin-dslΛ༗ޮʹ͢Δ࠷௿ݶͷఆٛ
    plugins {
    `kotlin-dsl`
    }
    repositories {
    jcenter()
    }

    View full-size slide

  72. extͷத਎ΛҠ͢
    buildSrc/src/main/kotlinʹDeps.ktΛ࡞੒
    object Depsʹvalͱ֤ͯ͠छఆ਺Λఆٛ

    View full-size slide

  73. ར༻Օॴͷॻ͖׵͑
    $kotlinVersion‎${Deps.kotlinVersion}
    Ұׅஔ׵ͱ͔ͰؤுΔ
    \$(\w+Version)ˠ\$\{Deps.$1\}
    rootProject\.ext\.(\w+)ˠDeps.$1

    View full-size slide

  74. ࢀরͰ͖ΔΑ͏ʹͳͬͯศར

    View full-size slide

  75. ͳΜ͔໘౗ͦ͘͞͏ͳͷ͕͋Δʜͬͯ࣌
    ྫ؀ڥม਺΍gitͷ৘ใΛextʹಥͬࠐΉ
    ,PUMJOͰॻ͖׵͑Ε͹͍͍Μ͚ͩͲɺޙճ͠ʹ͍ͨ͠

    View full-size slide

  76. ผϑΝΠϧʹ੾Γग़ͯ͠͠·͏
    ྫ͑͹ͦͷ··ci_vars.gradleͱͯ͠੾Γग़͢
    ݩͷ৔ॴʹapply from: "ci_vars.gradle"
    ,PUMJOԽͯ͠΋ͦͷ··Ͱ͍͍
    apply(from="ci_vars.gradle")
    ,PUMJO͔Β(SPPWZͷ(SBEMFϑΝΠϧΛݺ΂Δʂ

    View full-size slide

  77. ࣮ફฤτϐοΫ
    "OESPJE(SBEMF1MVHJOʹ্͛Δ
    ڊେextΛͳΜͱ͔͍ͨ͠
    ࣮͸,PUMJOεΫϦϓτ͔Β(SPPWZεΫϦϓτΛݺ΂Δ
    ϑΝΠϧͷ຤ඌʹapply plugin:͕͋Δ
    ͜ͷهड़ಈ͔ͳ͍ɺͲ͏͢Ε͹

    View full-size slide

  78. Ұ୴·Δͬͱ੾Γग़ͯ͠͠·͏ͱ͍͏େ୾ͳઓུ΋Մೳ
    // app/build.gradle.kts
    apply(from="original.build.gradle") // ͜ͷ1ߦ͚ͩ
    ‎ͦͷޙplugins {}ͱରԠ͢ΔઃఆΛҰͭͣͭҠ͍ͯ͘͠

    View full-size slide

  79. ྫkapt {}͚ͩҠߦ
    // app/build.gradle.kts
    plugins {
    kotlin("kapt")
    }
    apply(from="original.build.gradle")
    kapt {
    useBuildCache = true
    }

    View full-size slide

  80. ੾Γग़͢ͱ͖ͷ੍໿

    buildscript {}
    ͸੾Γग़ͤͳ͍
    ୯७ʹJODMVEFͯ͠ΔΘ͚Ͱͳ͘ϓϥάΠϯѻ͍
    ϑΝΠϧ͝ͱʹผͷDMBTTMPBEFSʹͳΔ

    it instanceOf AppPlugin
    తͳ൑ఆ͕ਖ਼͘͠ಈ࡞͠ͳ͍

    hasPlugin("com.android.application")
    ͸0,

    View full-size slide

  81. ࣮ફฤτϐοΫ
    "OESPJE(SBEMF1MVHJOʹ্͛Δ
    ڊେextΛͳΜͱ͔͍ͨ͠
    ࣮͸,PUMJOεΫϦϓτ͔Β(SPPWZεΫϦϓτΛݺ΂Δ
    ϑΝΠϧͷ຤ඌʹapply plugin:͕͋Δ
    ͜ͷهड़ಈ͔ͳ͍ɺͲ͏͢Ε͹

    View full-size slide

  82. ຤ඌʹ͋Δ͜Ε
    apply plugin: "com.google.gms.google-services"
    plugins {}ʹॻ͘ͱͦͷ࣌఺Ͱapply͞Εͯ͠·͏
    ਖ਼͘͠ಈ࡞͠ͳ͍

    View full-size slide

  83. idએݴʹapply falseΛ෇༩
    apply plugin:͸ݩͷҐஔʹஔ͍ͨ··
    plugins { // Groovy
    id "com.google.gms.google-services" apply false
    }
    plugins { // Kotlin
    id("com.google.gms.google-services") apply false
    }

    View full-size slide

  84. ࣮ફฤτϐοΫ
    "OESPJE(SBEMF1MVHJOʹ্͛Δ
    ڊେextΛͳΜͱ͔͍ͨ͠
    ࣮͸,PUMJOεΫϦϓτ͔Β(SPPWZεΫϦϓτΛݺ΂Δ
    ϑΝΠϧͷ຤ඌʹapply plugin:͕͋Δ
    ͜ͷهड़ಈ͔ͳ͍ɺͲ͏͢Ε͹

    View full-size slide

  85. repositories {}ฤ
    ଟ෼ਅͬઌʹҾ͔͔ͬΔ΍ͭ
    maven { url "https://plugins.gradle.org/m2/" }
    ɹɹɹɹɹɹɹɹ‑
    maven("https://plugins.gradle.org/m2/")

    RepositoryHandlerExtensions
    Ͱ֦ு͞Ε͍ͯΔ

    maven

    ivy

    View full-size slide

  86. sourceSets {}ฤ
    sourceSets { // Groovy
    main.java.srcDirs += 'src/main/kotlin'
    }
    ɹɹɹɹɹɹɹɹ‑
    sourceSets { // Kotlin
    getByName("main").java.srcDirs("src/main/kotlin")
    }
    (SPPWZ΋·ͬͨ͘ಉ͡ίʔυ͕௨Δ

    View full-size slide

  87. testOptions {}
    testOptions {
    unitTests { /* Closure Λظ଴͞ΕͯΔ */ }
    }

    View full-size slide

  88. ίʔυδϟϯϓͯ͠ΈΔ

    UnitTestOptions
    ܕͷઃఆΛ͢Δ$MPTVSFΒ͍͠
    ͜ͷܕ৘ใΛ,PUMJO%4-ʹ༩͑Δඞཁ͕͋Δ

    View full-size slide

  89. delegateClosureOf
    Ͱғͬͯ͋͛Δͱ
    unitTests( delegateClosureOf {} )
    ແࣄઃఆͰ͖ΔΑ͏ʹ

    View full-size slide

  90. ઃఆ͕·ͬͨ͘ॻ͚ͳ͍ &YUFOTJPO͕ෆՄࢹͳέʔε

    ྫHSBEMFBOESPJESJCCPOJ[FSQMVHJO
    this: Anyʜͩͱʜ

    View full-size slide

  91. &YUFOTJPOʹQVCMJD͕໌ࣔ͞Εͯͳ͍΍ͭ
    ribbonizerJTOPUBDDFTTJCMFJOBUZQFTBGFXBZCFDBVTF
    RibbonizerExtensionJTOPUQVCMJD
    (SPPWZͩͱΞΫηεͰ͖ΔΜ͚ͩͲͶʜ

    View full-size slide

  92. ࠷ޙͷखwithGroovyBuilderΛ࢖͏
    จࣈྻͰઃఆ஋ʹΞΫηεʢܕ΍Ҿ਺ͷݕ͕ࠪޮ͔ͳ͍ʣ
    ribbonizer {
    forcedVariantsNames("release")
    }
    ɹɹɹɹɹɹɹɹɹ‑
    ribbonizer {
    withGroovyBuilder {
    "forcedVariantsNames"("release")
    }
    }

    View full-size slide

  93. ༨ஊ৐Γӽ͑ͯ΋ࡉ͔͍ઃఆ͕Ͱ͖ͳ͔ͬͨͷͰ
    gradle-android-ribbonizer-pluginʹ͸γϡοͱ1VMM3FRVFTU
    Λ౤͛·ͨ͠

    View full-size slide

  94. ࣮ફฤ·ͱΊ
    ·ͣ"(1ʹ্͛Δ
    ڊେextΑΓ΋CVJME4SDʹ͢Δͱศར
    apply͸஗Ԇͤ͞ΒΕΔ
    େ͖ͳεΫϦϓτ͸੾Γग़ͤΔ
    Α͋͘Δهड़ͷॻ͖׵͑ύλʔϯΛ೺Ѳ

    View full-size slide

  95. େମ͜͜·ͰཧղͰ͖ͯΕ͹
    ΄ͱΜͲͷbuild.gradleΛ,PUMJOԽͰ͖Δ͸ͣ
    Ͳ͏ͯ͠΋μϝͳ෺͸(SPPWZʹ࢒͢

    View full-size slide

  96. ͓·͚ෆ۩߹ͬΆ͍΋ͷରԠࡦ
    ಥવkaptౖ͕Γग़͢
    'BCSJD1MVHJOͷalwaysUpdateBuildId্͕ख͘ಈ͔ͳ͍

    View full-size slide

  97. ಥવLBQUౖ͕Γग़͢
    ݱ৅4ZOD͸Ͱ͖͕ͨɺΞϓϦΛϏϧυ͢ΔͱLBQUౖ͕Γग़͠
    ͯϏϧυ͕௨Βͳ͍
    error: incompatible types: NonExistentClass cannot be
    converted to Annotation
    @error.NonExistentClass()
    ^
    ݪҼandroid-extensionsͷઃఆ͕൓ө͞Εͳ͍
    isExperimental = trueͬͯॻ͍ͯΔͷʹ൓ө͞Εͯͳ͍

    View full-size slide

  98. ճආࡦ
    configure(delegateClosureOf {})
    Ͱғ͏

    View full-size slide

  99. ,5
    IUUQTHJUIVCDPNHSBEMFLPUMJOETMJTTVFT
    LPUMJOBOESPJEͷઃఆ஋มߋϋϯυϦϯάपΓͷෆ۩߹

    View full-size slide

  100. 'BCSJDͷalwaysUpdateBuildId্͕ख͘ಈ͔ͳ͍
    Ϗϧυߴ଎Խͷ5JQTͰग़ͯ͘Δ΍ͭ
    buildTypes {
    debug {
    ext.alwaysUpdateBuildId = false
    }
    }
    by extraͰઃఆͯ͠΋൓ө͞Εͳ͍

    View full-size slide

  101. ճආࡦʮͲ͏ͯ͠΋μϝͳ΋ͷ͸ʯύλʔϯ
    ͜ͷߦ͚ͩผϑΝΠϧʹ੾Γग़ͯ͠BQQMZGSPN͢Δ
    // fabric.gradle
    android.buildTypes.debug.ext.alwaysUpdateBuildId = false
    // build.gradle.kts
    apply(file="fabric.gradle")
    BuildTypeʹઃఆ͞Εͨextͷ஋Λݟ͍ͯΔ͕ɺ
    ,PUMJO%4-͔ΒΞΫηεͰ͖ͳ͍

    View full-size slide

  102. ࿩ͨ͜͠ͱ
    ,PUMJOԽͷϝϦοτ

    !
    ଈ࠲ͷϑΟʔυόοΫɺ ϝϯςφϯεੑ޲্
    build.gradle.ktsʹҠߦ͢Δ࠶ݱՄೳͳखॱ
    ڞ௨ͷखॱ
    Α͋͘Δ໰୊ͱରԠࡦ

    View full-size slide

  103. ෭࣍తޮՌ
    !
    ϏϧυεΫϦϓτʹखΛೖΕΔ৺ཧతোนͷ௿Լ
    (SBEMFŧŔŕŪũƄŝſײ

    View full-size slide

  104. ࢀߟࢿྉ
    ,PUMJO$POG5ZQF4BGF#VJME-PHJDXJUI(SBEMF,PUMJO
    %4-CZ1BVM.FSMJO
    .JHSBUJOHCVJMEMPHJDGSPN(SPPWZUP,PUMJO
    (SBEMF,PUMJO%4-1SJNFS
    ެࣜͷ(SBEMF,PUMJO%4-ೖ໳υΩϡϝϯτ
    ެࣜͷҠߦΨΠυɺ(SPPWZͱ,PUMJO྆ํͰهड़͞ΕͯͯࢀߟʹͳΔ
    ,PUMJO%4-ͷதͷਓͷηογϣϯɺεϥΠυ

    View full-size slide