应用依赖和模块依赖/插件有什么区别? [英] What is the difference between an app dependency and a module dependency/plugin?

查看:584
本文介绍了应用依赖和模块依赖/插件有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用一些第三方库时,我在模块的build.gradle文件中添加了一个依赖项。

  compile'c​​om.android.support:appcompat-v7:24.1.1'

或者我添加一个插件

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

其他时候,该库需要添加一个依赖项我的应用程序的build.gradle文件。

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

这些依赖和插件有什么不同?

为什么不能全部是设置在一个单一的build.gradle文件?



所有建议表示赞赏,我无法搜索有关此信息

解决方案

三件事。 Gradle 插件,模块依赖关系,它是放置在构建工具的 classpath 上的构建依赖项。



插件是Gradle如何知道任务来使用。有插件。有关更多信息,请参见 Gradle - 插件文档



依赖关系一个用你的代码编译的库。以下行使您的模块依赖于Android AppCompat V7库。大多数情况下,您搜索 Maven Jcenter

  compile'c​​om.android.support:appcompat-v7:24.1.1'

classpath 设置为需要Gradle ,而不是您的应用。例如,这允许将Android的Gradle Build Tools包括到类路径中,并允许Gradle构建应用程序。

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




为什么它们不能全部放在一个build.gradle文件中?
blockquote>

他们可能是。它不是更模块化。

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

解决方案

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.

这篇关于应用依赖和模块依赖/插件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆