Gradle dependency difference between compiler, apk project, compilation project provided, implementation project

Gradle difference between values.

compile apk project compile project provided project implementation 

My questions

What is the difference between compile , apk project , compile project , provided project here?

+6
source share
1 answer

There are two separate topics here: Dependency configurations and dependency sources.

Dependency Configurations

Configurations help determine the transitivity of a dependency, which in turn eliminates the pain of having to discover and specify the libraries your own project / library needs, including them automatically. This concept of configurations in gradle is very similar to the concept of Maven Scopes :

  • compile : Compile dependencies are available in all classes of the project. In addition, these dependencies apply to dependent projects. At run time, a compile time dependency is usually required.
  • apk : defines runtime dependency. Dependence on this area is not required at compile time, but it will be executed. This means that you can save time during compilation and still have the dependency available when your project really works. This is a good example of when to use the apk dependency.
  • provided : This means that this dependency is available at runtime. As a result, this scope is accessible only on the way of compilation and testing of the class and is not transitive. It is not supported on Android projects, although you can get around it by specifying your own configuration, as discussed here .

There are more configurations on Android, such as testCompile , which allows you to specify a compile-time dependency that will be used only for testing, for example, you want to use junit in your tests, and then you will do the following:

 testCompile 'junit:junit:4.12' 

Source of addiction

Once you understand the configurations available to you, you need to specify the actual dependency. Dependencies can be internal or external, you can rely on another library that you are working on, as well as on public libraries. This is where the project keyword is included, allowing you to specify a dependency on an internal module or library. By defining the dependency as a compile project , you add this module or library as a transitive dependency on your project.

Suppose you have a messages project with three modules ( producer , consumer and shared ), the project structure will look like this:

 messages/ build.gradle settings.gradle consumer/ build.gradle producer/ build.gradle shared/ build.gradle 

Suppose both consumer and producer save messages in json format and that you want to use google-gson for this purpose. Suppose both projects have some common source code that they depend on, your shared module. consumer build.gradle can identify the following dependencies:

 dependencies { // Internal dependency to project shared compile project (':shared') // External dependency to publicly available library, // through public repositories such as jcenter() or mavencentral() compile 'com.google.code.gson:gson:1.7.2' } 

To summarize, this is a combination of two configurations and sources that allow you to declare dependencies as compile , compile project , apk project and more

+9
source

All Articles