什么是Kotlin Gradle依赖项中的"实现"?

ald*_*dok 8 android gradle kotlin android-gradle-plugin

我正在使用Android Studio 3.0 Preview来启动新的Kotlin项目.当我尝试在build.gradle我看到implementation范围而不是通常时添加依赖项compile.

androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:25.3.1'
testImplementation 'junit:junit:4.12'
Run Code Online (Sandbox Code Playgroud)

还有androidTestImplementationtestImplementation范围.

最后,我添加compile添加第三方依赖项,它的工作原理.

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
Run Code Online (Sandbox Code Playgroud)

所以我的问题是......

  • 是什么implementation,androidTestImplementationtestImplementation范围是什么?
  • 它比任何不同compile,testCompileandroidTestCompile
  • 我应该在Kotlin项目中使用哪一个?

编辑:我的不好,这个问题不是Kotlin具体的.这是新的Android Gradle Plugin配置.

nha*_*man 20

这不是Kotlin特有的,而是与Android的新Gradle插件有关.

compile,providedapk现在已过时.
使用implementationapi代替compile,compileOnly代替providedruntimeOnly代替的apk.

这样做的原因是为了加速多模块构建.给定A依赖于模块的模块B又依赖于模块C,模块的改变C也会触发模块的重新编译A.如果AC直接使用,则无需AC更改时重新编译.

implementation配置可确保正是这一点:如果您指定implementation project(':C')B,则无法访问CA你避免不必要的构建模块.在大型多模块项目中,这可以节省大量时间.

有关详细信息,请参阅迁移到新的Gradle插件.