Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "implementation" in Kotlin Gradle dependencies?

I'm using Android Studio 3.0 Preview to start new Kotlin project. As I try to add dependencies in build.gradle I saw implementation scope instead of usual 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'

There's also androidTestImplementation and testImplementation scope.

In the end, I add compile to add third party dependencies and it works.

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

So my questions are..

  • What is implementation, androidTestImplementation, and testImplementation scope?
  • Is it any different than compile, testCompile, and androidTestCompile?
  • Which one I should use for my Kotlin project?

Edit: My bad, this question is not Kotlin specific. It's the new Android Gradle Plugin configuration.

like image 944
aldok Avatar asked Jun 09 '17 08:06

aldok


People also ask

What are implementation dependencies?

Implementation dependencies : The references used in the relations between components are typed using concrete classes or abstract classes. Interface dependencies: The references used in the relations between components are typed using only interfaces.

What is difference between compile and implementation in Gradle?

Fortunately, the implementation dependency configuration provides the same functionality as compile. You should always use implementation rather than compile for dependencies, as compile is now deprecated or removed in the case of Gradle 7+.

What is dependencies in Gradle?

Dependencies refer to the things that supports in building your project, such as required JAR file from other projects and external JARs like JDBC JAR or Eh-cache JAR in the class path. Publications means the outcomes of the project, such as test class files, build files and war files.

What are dependencies in Kotlin?

Dependency on a Kotlin library A dependency on a standard library ( stdlib ) in each source set is added automatically. The version of the standard library is the same as the version of the kotlin-multiplatform plugin.


1 Answers

This is not specific to Kotlin, but has to do with the new Gradle plugin for Android.

compile, provided and apk are now deprecated.
Use implementation or api instead of compile, compileOnly instead of provided, and runtimeOnly instead of apk.

The reason for this is to speed up multi-module builds. Given module A which depends on module B which in turn depends on module C, a change in module C would trigger a recompile of module A as well. If A does not use C directly, there is no need for A to recompile when C changes.

The implementation configuration ensures exactly this: if you specify implementation project(':C') in B, you cannot access C from A and you avoid building unnecessary modules. In a large multi-module project this can save a lot of time.

See Migrate to the new Gradle plugin for more information.

like image 158
nhaarman Avatar answered Sep 28 '22 09:09

nhaarman