build.gradle.kts

3295d80faee461db1093982361256fe4?s=47 Panini
October 19, 2018

 build.gradle.kts

build.gradleをKotlinに書き換えた話
チラッと導入仕方と罠を紹介します

3295d80faee461db1093982361256fe4?s=128

Panini

October 19, 2018
Tweet

Transcript

  1. 2.

    About Me • Matthew Vern / Panini • Twitter: @callipan

    Github: panpanini • Mercari, Inc • Android Engineer (US) • Kotlin可愛い
  2. 6.

    How to • No auto-convert • Almost the same as

    Groovy, so can copy-paste, or write by hand
  3. 7.
  4. 10.

    buildSrc/Dependencies.kt object Versions { val supportLibrary = "27.1.0" ... }

    object Dependencies { // support val supportV4 = "com.android.support:support-v4:${Versions.supportLibrary}" }
  5. 13.

    app/build.gradle.kts plugins { id(Plugins.unusedResourceRemover) } repositories { maven("https://hoge.com/gradle/gradle-release/") { credentials.username

    = Credentials.hogeUsername credentials.password = Credentials.hogePassword } } dependencies { implementation(Dependencies.supportV4) releaseImplementation(ReleaseDependencies.hoge) }
  6. 16.

    app/build.gradle FAILURE: Build failed with an exception. * Where: Build

    file '/app/build.gradle.kts' line: 4 * What went wrong: Script compilation error: Line 4: classpath(BuildScriptDependencies.removeResourcesPlugin) ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public final fun DependencyHandler.classpath(dependencyNotation: Any): Dependency? defined in org.gradle.kotlin.dsl.ScriptHandlerScope
  7. 20.

    app/build.gradle • Gradle: buildscript { } → 追加 • Kotlin:

    buildscript { } → 上書き ↳ buildscriptはroot/build.gradle.ktsで書く
  8. 21.

    app/build.gradle • Gradle: buildscript { } → 追加 • Kotlin:

    buildscript { } → 上書き ↳ buildscriptはroot/build.gradle.ktsで書く 本当にこれでいいのか分からないので 他にいいアイデアあれば是非聞かせて ください!
  9. 24.

    app/build.gradle FAILURE: Build failed with an exception. IllegalStateException: 'android' or

    'android-library' plugin required. plugins { } を使うと同時にapplyされるっぽい
  10. 25.

    app/build.gradle FAILURE: Build failed with an exception. IllegalStateException: 'android' or

    'android-library' plugin required. plugins { } を使うと同時にapplyされるっぽい この問題gradle-4.10.2で 治ってるっぽい!
  11. 26.