【问题标题】:Configuring "build.gradle" for Kotlin module in Android Studio在 Android Studio 中为 Kotlin 模块配置“build.gradle”
【发布时间】:2016-04-21 16:53:34
【问题描述】:

我正在开发一个应用程序,我想将 Android 特定逻辑与业务逻辑(“不可变”逻辑和 Android 独立)分开,所以我创建了两个模块:

  • app:Android 特定代码
  • :业务逻辑(用 Kotlin 编写)

我将这个 build.gradle 文件用于 kotlin 模块

apply plugin: 'kotlin'

kapt {
    generateStubs = true
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    /* Annotations library */
    provided 'org.glassfish:javax.annotation:10.0-b28'
    kapt 'com.google.dagger:dagger-compiler:2.0.1'

    /* Dagger 2 library */
    compile 'com.google.dagger:dagger:2.0.1'

   /* EventBus library */
   compile 'de.greenrobot:eventbus:2.4.0'

   /* JODA TIME - time and date library */
   compile 'joda-time:joda-time:2.9.2'

  /*Rx Kotlin*/
  compile 'io.reactivex:rxkotlin:0.55.0'

  testCompile 'junit:junit:4.12'
  testCompile 'org.mockito:mockito-core:2.0.47-beta'
}

buildscript {

    ext.kotlin_version = '1.0.1-2'

    repositories {
        mavenCentral()
    }

    dependencies {

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    }
}

repositories {
    mavenCentral()
    maven{ url "http://repository.jetbrains.com/all" }
}

这是配置 kotlin 模块的正确方法吗?

PLUS:我收到 Gradle DSL 方法未找到:'provided()' 错误。我该如何解决?

【问题讨论】:

    标签: android gradle kotlin


    【解决方案1】:

    Gradle 默认没有provided 配置。相反,它有compileOnly。因此,如果您真的希望依赖项仅在编译期间可用,请执行以下操作:

    compileOnly 'org.glassfish:javax.annotation:10.0-b28'
    

    【讨论】:

      猜你喜欢
      • 2015-04-18
      • 2021-07-04
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 2021-05-13
      • 2014-10-02
      • 1970-01-01
      • 2022-12-28
      相关资源
      最近更新 更多