Building Android Projects with kts

Building Android Projects with kts

Presentation Build Android Projects with kts.
Devfest Latam 2020
Devfest Pacific Region DevFest 2020

32018c62accb6edf57251e04308d4216?s=128

Iñaki Villar

October 18, 2020
Tweet

Transcript

  1. None
  2. None
  3. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } }
  4. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  5. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  6. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  7. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  8. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  9. None
  10. None
  11. None
  12. None
  13. None
  14. None
  15. KTS

  16. GRADLE JAVA API KTS

  17. GRADLE JAVA API KTS Kotlin DSL API org.gradle.kotlin.dsl org.gradle.kotlin.dsl.plugins.dsl

  18. GRADLE JAVA API KTS Kotlin DSL API org.gradle.kotlin.dsl org.gradle.kotlin.dsl.plugins.dsl implementation("com.github.oshi:oshi-core:3.13.3")

  19. GRADLE JAVA API KTS Kotlin DSL API org.gradle.kotlin.dsl org.gradle.kotlin.dsl.plugins.dsl implementation("com.github.oshi:oshi-core:3.13.3")

    fun DependencyHandler.`implementation`(dependencyNotation: Any): Dependency? = add("implementation", dependencyNotation)
  20. Gradle

  21. kotlin-compiler-embeddable Gradle

  22. kotlin-compiler-embeddable kotlin-stdlib kotlin-reflect Gradle

  23. 6.8 kotlin-compiler-embeddable kotlin-stdlib kotlin-reflect Gradle 1.4 6.6 1.3 Gradle Kotlin

  24. Module-a/build.gradle.kts

  25. dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") } Module-a/build.gradle.kts

  26. dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") } Module-a/build.gradle.kts object Dependencies { const

    val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:1.3.60" const val influxDb = "org.influxdb:influxdb-java:2.19" }
  27. dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") } Module-a/build.gradle.kts object Dependencies { const

    val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:1.3.60" const val influxDb = "org.influxdb:influxdb-java:2.19" } dependencies { implementation(Dependencies.kotlin) implementation(Dependencies.influxDb) }
  28. dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") } Module-a/build.gradle.kts object Dependencies { const

    val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:1.3.60" const val influxDb = "org.influxdb:influxdb-java:2.19" } dependencies { implementation(Dependencies.kotlin) implementation(Dependencies.influxDb) }
  29. Module-b/build.gradle.kts

  30. Module-b/build.gradle.kts dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") }

  31. Module-b/build.gradle.kts dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") }

  32. Module-b/build.gradle.kts dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") } Module a Module b

    build.gradle.kts build.gradle.kts
  33. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API

  34. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API

  35. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API

  36. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API dependencies

    { implementation("") implementation("") testImplementation("") } object Dependencies{ ... }
  37. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API plugins

    { `kotlin-dsl` }
  38. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API plugins

    { `kotlin-dsl` } import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.repositories class ExamplePlugin : Plugin<Project> { override fun apply(target: Project) { target.repositories { } target.dependencies { } } }
  39. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API

  40. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API buildscript

    { repositories { google() jcenter() } dependencies { classpath("com.android.tools.build:gradle:4.1.0") classpath(kotlin("gradle-plugin", version = "1.3.70")) } } plugins { id("com.android.application") kotlin("android") kotlin("android.extensions") }
  41. buildSrc buildScript Plugins Gradle Module a build.gradle.kts Module b build.gradle.kts

  42. buildSrc buildScript Plugins Gradle Module a build.gradle.kts Module b build.gradle.kts

  43. buildSrc buildScript Plugins Gradle Module a build.gradle.kts Module b build.gradle.kts

  44. buildSrc buildScript Plugins Gradle Module a build.gradle.kts Module b build.gradle.kts

  45. buildSrc buildScript Plugins Gradle Module a build.gradle.kts Module b build.gradle.kts

    Cache invalidation!!
  46. Java Platform Plugin

  47. Java Platform Plugin dependencies { constraints { api("commons-httpclient:commons-httpclient:3.1") api("org.apache.commons:commons-lang3:3.8.1") }

    }
  48. Java Platform Plugin dependencies { constraints { api("commons-httpclient:commons-httpclient:3.1") api("org.apache.commons:commons-lang3:3.8.1") }

    } dependencies { api(platform(project(":platform"))) api("commons-httpclient:commons-httpclient") }
  49. Java Platform Plugin dependencies { constraints { api("commons-httpclient:commons-httpclient:3.1") api("org.apache.commons:commons-lang3:3.8.1") }

    } dependencies { api(platform(project(":platform"))) api("commons-httpclient:commons-httpclient") } https://docs.gradle.org/current/userguide/java_platform_plugin.html
  50. refreshVersions https://github.com/jmfayard/refreshVersions

  51. AGP 4.1

  52. AGP 4.1 Full Support Kotlin DSL

  53. AGP 4.1 Full Support Kotlin DSL API & DSL Kotlin

    https://developer.android.com/reference/tools/gradle-api/4.1/com/android/build/api/dsl/ApplicationBaseFlavor
  54. AGP 4.1 Full Support Kotlin DSL API & DSL Kotlin

  55. AGP 4.1 Full Support Kotlin DSL API & DSL Kotlin

  56. KTS = Kotlin in GRADLE SUPPORT AGP 4.1 BUILD SYSTEM

    INTERNALS BUILD LOGIC > KTS
  57. https://github.com/gradle/kotlin-dsl-samples https://medium.com/androiddevelopers/new-apis-in-the-android-gradle-plugin-f5325742e614 https://guides.gradle.org/migrating-build-logic-from-groovy-to-kotlin/ https://github.com/androidx/androidx AGP 4.1 MIGRATION SAMPLES ANDROIDX IDIOMATIC

    https://github.com/jjohannes/idiomatic-gradle Resources
  58. BUILD SUCCESSFUL in 30m 50s Thanks @inyaki_mwc