简体   繁体   中英

Some questions about Gradle for Android Development

I have some questions about Gradle.

  1. What is the difference between buildscript.dependencies and dependencies ?
  2. What is the difference between classpath and compile ?
  3. What does apply plugin: mean?

Just check their docs, they have described it well. But here is it: 1:

If your build script needs to use external libraries, you can add them to the script's classpath in the build script itself. You do this using the buildscript() method, passing in a closure which declares the build script classpath.

This is good for external dependencies (for example from internet repos which are in buildscript part too.)


2: Docs with table and descriptions for each. compile will get dependencies during compiling. (for example you can set 'runtime' and these dependencies will be used during runtime, or testCompile will be used only during compiling tests). This is very important! Read their docs. Of course you can try to compile everything everytime, but this is really bad idea. Good example are JUnit tests, you need JUnit only during compiling tests co then you use compileTest:

 testCompile "junit:junit:X.YZ"

3: It means that you applied plugin :) You apply java, or when you need spring or spring boot, then you simply can tell Gradle, hey Gradle, I am going to using this, so aplly it. More here .

I suggest you download the full Gradle distribution, only because it provides a PDF version of the User Guide (I don't know of any other way to get the user guide PDF). Read it from top to bottom, skipping chapters that are clearly irrelevant to you. You will get answers to all of these questions, and more that you haven't asked yet.

However, I'll give you some brief answers.

Q1: Gradle has dependencies for the build script, and dependencies for the code you're building. They are separate.

Q2: Classpath is a runtime notion used by Java, which Gradle utilizes in different ways. Compile is a "configuration" which you can add dependencies to, which affects the eventual runtime classpath.

Q3: "apply plugin" is applying a Gradle plugin. Read the user guide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM