在Android Studio中为Kotlin模块配置“build.gradle”

我正在开发一个应用程序,我想从业务逻辑(“不可变”的逻辑和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模块的正确方法吗?

PLUS:我得到一个没有findGradle DSL方法:’provided()’错误。 我怎么解决它?

Gradle默认没有provided配置。 相反,它只compileOnly 。 所以,如果你真的想要一个依赖只有在编译期间可用,请执行以下操作:

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