Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between an app dependency and a module dependency/plugin?

When using some 3rd party libraries, I add a dependency to my module's build.gradle file.

    compile 'com.android.support:appcompat-v7:24.1.1' 

Or I add a plugin

    apply plugin: 'com.neenbedankt.android-apt' 

Some other times, the library requires adding a dependency to my app's build.gradle file.

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 

What is the difference between these dependencies and plugins?
Why can't they all be set in a single build.gradle file?

All suggestions are appreciated, I'm having trouble searching for info on this

like image 735
Daiwik Daarun Avatar asked Aug 12 '16 04:08

Daiwik Daarun


People also ask

What's the difference between plug ins and dependencies?

A plugin is an extension to Maven, something used to produce your artifact (maven-jar-plugin for an example, is used to, you guess it, make a jar out of your compiled classes and resources). A dependency is a library that is needed by the application you are building, at compile and/or test and/or runtime time.

What is the difference between plugins and dependencies in Gradle?

Gradle will use the added plugins at the time of building the App. Dependecies are used to add some addtional code to your source code, so a dependency will make some extra code (like Classes in Java) in the form of library available for your source code.

What is dependency Management plugin?

The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

What are Gradle plugins?

A plugin is simply any class that implements the Plugin interface. Gradle provides the core plugins (e.g. JavaPlugin ) as part of its distribution which means they are automatically resolved. However, non-core binary plugins need to be resolved before they can be applied.


2 Answers

Three things. Gradle plugin, module dependency, a build dependency which is placed on the classpath of the build tool.

A plugin is how Gradle knows what tasks to use. There are many plugins. For more info, see Gradle - Plugin Documentation

A dependency is a library that is compiled with your code. The following line makes your module depend on the Android AppCompat V7 library. For the most part, you search Maven or Jcenter for these.

compile 'com.android.support:appcompat-v7:24.1.1' 

The classpath setting is needed for Gradle, not your app. For example, this allows this includes the Gradle Build Tools for Android into the classpath, and allows Gradle to build apps.

classpath 'com.android.tools.build:gradle:2.1.2' 

Why can't they all be in one build.gradle file?

They probably can be. It is simply more modular to not.

like image 130
OneCricketeer Avatar answered Sep 27 '22 23:09

OneCricketeer


I got this answer from a colleague, and this helped me understand. "A gradle plugin is like the tools you use to build the app. The dependencies are the libraries included in the app. A gradle plugin is usually the tasks - like ktlint, etc."

like image 40
Surekha Avatar answered Sep 28 '22 00:09

Surekha