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

build.gradle.kts

Panini
October 19, 2018

 build.gradle.kts

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

Panini

October 19, 2018
Tweet

More Decks by Panini

Other Decks in Technology

Transcript

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

    Github: panpanini • Mercari, Inc • Android Engineer (US) • Kotlin可愛い
  2. How to • No auto-convert • Almost the same as

    Groovy, so can copy-paste, or write by hand
  3. buildSrc/Dependencies.kt object Versions { val supportLibrary = "27.1.0" ... }

    object Dependencies { // support val supportV4 = "com.android.support:support-v4:${Versions.supportLibrary}" }
  4. 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) }
  5. 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
  6. app/build.gradle • Gradle: buildscript { } → 追加 • Kotlin:

    buildscript { } → 上書き ↳ buildscriptはroot/build.gradle.ktsで書く
  7. app/build.gradle • Gradle: buildscript { } → 追加 • Kotlin:

    buildscript { } → 上書き ↳ buildscriptはroot/build.gradle.ktsで書く 本当にこれでいいのか分からないので 他にいいアイデアあれば是非聞かせて ください!
  8. app/build.gradle FAILURE: Build failed with an exception. IllegalStateException: 'android' or

    'android-library' plugin required. plugins { } を使うと同時にapplyされるっぽい
  9. app/build.gradle FAILURE: Build failed with an exception. IllegalStateException: 'android' or

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