簡體   English   中英

在Android Studio中為Kotlin模塊配置“ build.gradle”

[英]Configuring “build.gradle” for Kotlin module in Android Studio

我正在開發一個應用程序,並且想要將Android特定邏輯與業務邏輯(“不可變”邏輯和Android獨立)分開,因此我創建了兩個模塊:

  • 應用 :Android特定代碼
  • 領域 :業務邏輯(用Kotlin編寫)

我正在為kotlin模塊使用這個build.gradle文件

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模塊的正確方法嗎?

加上:我收到未找到Gradle DSL方法:“ provided()”錯誤。 我該如何解決?

Gradle默認沒有provided配置。 相反,它具有compileOnly 因此,如果您確實希望依賴項僅在編譯期間可用,請執行以下操作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM