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

Kotlin-Flavored BuildScripts

Kotlin-Flavored BuildScripts

> Kotlin Korea Meetup 2018

# 코틀린 맛 빌드스크립트

코틀린으로 그래들 플러그인을 만들고, 이미 존재하는 그래들 프로젝트에서 사용하는 방법을 소개합니다.
그루비로 되어있는 그래들 프로젝트를 점차 코틀린으로 바꾸는 방향을 제안합니다.

https://github.com/importre/kotlin-flavored-buildscripts

Jaewe Heo

June 26, 2018
Tweet

More Decks by Jaewe Heo

Other Decks in Programming

Transcript

  1. @importre • Jaewe Heo ೲ੤ਤ @ !iiid! ܡ੉٘! • Kotlin

    Korea • Android • ReactiveX • Probot for Github automation • ...
  2. ׼न਷ • Kotlin • Gradle • Gradle with Kotlin DSL1

    1 kotlin-dsl: Kotlin language support for Gradle build scripts
  3. Բ৉Բ৉ • ҅ࣘ ӡয૑ח build.gradle • apply from: ...? •

    ೒۞Ӓੋ? • Groovy • ز੸ ೐۽Ӓې߁ ঱য • ੗ز৮ࢿ !
  4. buildSrc೐۽ં౟ $rootProject/buildSrc/ • ೒۞Ӓੋ ௏٘ܳ ੘ࢿೞݶ • ࠽٘झ௼݀౟ classpathী ನೣغয

    • ݫੋ/ࢲ࠳ ݽٕٜ੄ ࠽٘झ௼݀౟ীࢲ ࢎਊ оמ • ҕਬ ࠛо • ݫੋ ݽٕਸ ߩযաݶ ॶ ࣻ হ਺
  5. (SBEMFীٮܲ,PUMJO%4-ߡ੹ Gradle Wrapper Kotlin DSL Kotlin 4.8 0.17.5 1.2.4x 4.7

    0.16.3 1.2.3x 4.6 0.15.6 1.2.2x 2 Releases: https://github.com/gradle/kotlin-dsl/releases
  6. GreetingPlugin GFBUbuildSrc 1. buildSrc ٣۩షܻ ࢤࢿ 2. buildSrc/build.gradle.kts ࢤࢿ 3.

    Ӓېٜ ೒۞Ӓੋ ߂ కझ௼ ੘ࢿ 4. ӝઓ ࠽٘झ௼݀౟build.gradle ী ੸ਊ 5. కझ௼ प೯
  7. Ӓېٜ೒۞Ӓੋ߂కझ௼੘ࢿ class GreetingPlugin : Plugin<Project> { private fun greeting(): String

    = "Hello, World!" override fun apply(project: Project): Unit = project.run { tasks { "greeting" { group = "kotlin-flavored" description = "௏ౣܽ ݍ Ӓېٜ ೒۞Ӓੋ" doLast { .run( ::println) } } } } }
  8. Ӓېٜ೒۞Ӓੋ߂కझ௼੘ࢿ class GreetingPlugin : Plugin<Project> { private fun greeting(): String

    = "Hello, World!" override fun apply(project: Project): Unit = project.run { tasks { "greeting" { group = "kotlin-flavored" description = "௏ౣܽ ݍ Ӓېٜ ೒۞Ӓੋ" doLast { greeting().run( ::println) } } } } }
  9. Ӓېٜ೒۞Ӓੋ߂కझ௼੘ࢿ class GreetingPlugin : Plugin<Project> { private fun greeting(): String

    = "Hello, World!" override fun apply(project: Project): Unit = project.run { tasks { "greeting" { group = "kotlin-flavored" description = "௏ౣܽ ݍ Ӓېٜ ೒۞Ӓੋ" doLast { greeting().run( ::println) } } } } }
  10. Ӓېٜ೒۞Ӓੋ߂కझ௼੘ࢿ class GreetingPlugin : Plugin<Project> { private fun greeting(): String

    = "Hello, World!" override fun apply(project: Project): Unit = project.run { tasks { "greeting" { group = "kotlin-flavored" description = "௏ౣܽ ݍ Ӓېٜ ೒۞Ӓੋ" doLast { greeting().run( ::println) } } } } }
  11. ࢤࢿೠ೒۞Ӓੋ֢୹ plugins { `kotlin-dsl` `java-gradle-plugin` } gradlePlugin { (plugins) {

    "greeting-plugin" { id = "greeting" implementationClass = "importre.GreetingPlugin" } } } 3 java-gradle-plugin: https://docs.gradle.org/current/userguide/java_gradle_plugin.html
  12. ࢤࢿೠ೒۞Ӓੋ֢୹ plugins { `kotlin-dsl` `java-gradle-plugin` } gradlePlugin { (plugins) {

    "greeting-plugin" { id = "greeting" implementationClass = "importre.GreetingPlugin" } } } 3 java-gradle-plugin: https://docs.gradle.org/current/userguide/java_gradle_plugin.html
  13. ࢤࢿೠ೒۞Ӓੋ֢୹ plugins { `kotlin-dsl` `java-gradle-plugin` } gradlePlugin { (plugins) {

    "greeting-plugin" { id = "greeting" implementationClass = "importre.GreetingPlugin" } } } 3 java-gradle-plugin: https://docs.gradle.org/current/userguide/java_gradle_plugin.html
  14. ࢤࢿೠ೒۞Ӓੋ֢୹ plugins { `kotlin-dsl` `java-gradle-plugin` } gradlePlugin { (plugins) {

    // As an expression "greeting-plugin" { id = "greeting" implementationClass = "importre.GreetingPlugin" } } } 3 java-gradle-plugin: https://docs.gradle.org/current/userguide/java_gradle_plugin.html
  15. ੊झబ࣌ࢤࢿ package importre /** * [GreetingPlugin] Extension * * @property

    userName for **greeting ** */ open class GreetingExt( var userName: String? = null )
  16. కझ௼ীݒೝ class GreetingPlugin : Plugin<Project> { private fun greeting(userName: String?)

    = "Hello, ${userName ?: "World"}!" override fun apply(project: Project): Unit = project.run { val ext = extensions.create("greeting", GreetingExt ::class.java) tasks { "greeting" { group = "kotlin-flavored" description = "௏ౣܽ ݍ Ӓېٜ ೒۞Ӓੋ" doLast { greeting(ext.userName).run( ::println) } } } } }
  17. కझ௼ীݒೝ class GreetingPlugin : Plugin<Project> { private fun greeting(userName: String?)

    = "Hello, ${userName ?: "World"}!" override fun apply(project: Project): Unit = project.run { val ext = extensions.create("greeting", GreetingExt ::class.java) tasks { "greeting" { group = "kotlin-flavored" description = "௏ౣܽ ݍ Ӓېٜ ೒۞Ӓੋ" doLast { greeting(ext.userName).run( ::println) } } } } }
  18. GreetingPlugin GFBU4UBOEBMPOF 1. ݃਺؀۽ ٣۩షܻ ࢤࢿ 2. ೒۞Ӓੋ ҳഅ 3.

    ӝઓ ࠽٘झ௼݀౟৬ Composit 4. ӝઓ ࠽٘झ௼݀౟build.gradle ী ੸ਊ 5. కझ௼ प೯
  19. DGgradle init Task name Type Description init InitBuild Generates a

    Gradle project • Types of InitBuild • java-application • java-library • scala-library • ... • basic
  20. DGgradle initXJUIkotiln-dsl $ gradle init --type java-library --dsl kotlin $

    tree . ├── build.gradle.kts ├── gradle │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src ├── main │ └── java │ └── Library.java └── test └── java └── LibraryTest.java 7 directories, 8 files
  21. DGgradle initXJUIkotiln-dsl $ gradle init --type java-library --dsl kotlin $

    tree . ├── build.gradle.kts ├── gradle │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src ├── main │ └── java │ └── Library.java └── test └── java └── LibraryTest.java 7 directories, 8 files
  22. $PNQPTJU#VJMET • ݣ౭ ࠽٘৬ ࠽तೞա ة݀੸ਵ۽ ѐߊೞҊ ನೣदఆ ࣻ ੓਺

    • include؀न includeBuild ೣࣻܳ ࢎਊ • settings.gradle੉ ੓যঠ ೣ • ӝઓ ೐۽ં౟੄ ੉ܴҗ ઺ࠂೲਊ ࠛо 4 Composite Builds: https://docs.gradle.org/current/userguide/composite_builds.html
  23. ӝઓ࠽٘झ௼݀౟build.gradleী੸ਊ buildscript { dependencies { classpath 'com.importre.example:greeting' } } apply

    plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'greeting' android {
  24. ӝઓ࠽٘झ௼݀౟build.gradleী੸ਊ buildscript { dependencies { classpath 'com.importre.example:greeting' } } apply

    plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'greeting' android {
  25. ਃড • buildSrc ೐۽ં౟ • buildSrc ࢤࢿ • ೒۞Ӓੋ ҳഅ

    • ӝઓ ೐۽ં౟ী ೒۞Ӓੋ ੸ਊ • ೒۞Ӓੋ ഛ੢ ҳഅ ߂ ੸ਊ • ة݀੸ੋStandalone ೐۽ં౟ • ೒۞Ӓੋ ೐۽ં౟ ࢤࢿ • ೒۞Ӓੋ ҳഅ • ӝઓ ೐۽ં౟ী ೒۞Ӓੋ ನೣ • ӝઓ ೐۽ં౟ী ೒۞Ӓੋ ੸ਊ
  26. ݃ޖܻ • ੉޷ ழ૓ झ௼݀౟ܳ ೠߣী gradle.build.kts۽ ৤ӝӝূ ൨ٝ •

    ೞաঀ ৤ѹࢲ build.gradle ୭ࣗച • ੘ই૓ build.gradleਸ build.gradle.kts۽ ߸ജ
  27. ઁউ • buildSrc ೐۽ં౟ • ই૒ হ׮ݶ ੉઱ द੘ •

    ة݀੸ੋStandalone ೐۽ં౟ • ੉޷ buildSrcо ੓Ѣա • ݧ૓ ೒۞Ӓੋਸ ҳഅ ߂ ҕਬ & ߓನ
  28. WE ARE HIRING! !iiid! : AI-based EdTech • যରೖ ؋૕ೡѢ

    ೯ࠂೞѱ ؋૕ೞ੗ • ࢑ఋష੊ • ష੊೟ਗ ӝࣿഥࢎ • ...
  29. ನ૑࣌ • AI Scientist / Data Engineer • Android •

    Backend • iOS • or Something else • e.g. Content Developers Headless CMS5 5 CMS: Content Management System