What's the difference between implementation and compile in Gradle?

前端 未结 9 1495
北荒
北荒 2020-11-22 03:01

After updating to Android Studio 3.0 and creating a new project, I noticed that in build.gradle there is a new way to add new dependencies instead of comp

9条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 03:27

    • implementation: mostly we use implementation configuration. It hides the internal dependency of the module to its consumer to avoid accidental use of any transitive dependency, hence faster compilation and less recompilation.

    • api: must be used very carefully, since it leaks the to consumer’s compile classpath, hence misusing of api could lead to dependency pollution.

    • compileOnly: when we don’t need any dependency at runtime, since compileOnly dependency won’t become the part of the final build. we will get a smaller build size.

    • runtimeOnly: when we want to change or swap the behaviour of the library at runtime (in final build).

    I have created a post with an in-depth understanding of each one with Working Example: source code

    https://medium.com/@gauraw.negi/how-gradle-dependency-configurations-work-underhood-e934906752e5

提交回复
热议问题