Nikolai
03/22/2019, 2:13 AMbuildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
repositories {
google()
jcenter()
}
The main thing what I don't understand is purpose of 'buildscript' section,
I mean why not put everything outside of this section? What is the difference between 'repositories' inside and outside 'buildscript' (btw where is another project included into parent 'app' and it have his own 'repositories' section inside his build.gradle file )?Casey Brooks
03/22/2019, 2:35 AM.gradle
files are code. Specifically, Groovy code (or optionally, Kotlin). They are not markup files like Maven’s pom.xml
or NPM’s package.json
, it is actually real code that Gradle will compile ane execute when you run your Gradle build. That first block in the root build.gradle
file for buildscript
is used to configure that initial compilation step. Before it can run any plugins, you have to tell Gradle where it can find them and how it can include them in the script’s classpath so that it can even properly execute the rest of the code in that script and the other build.gradle
scripts. The dependencies in the buildscript
block never touch your application code.
From there, Gradle separates a full “build” into “projects” which roughly correspond to your project’s top-level directories. First, the root directory becomes a project, and then app
becomes a second “project”, and so on with settings.gradle
being executed to determine the exact locations of those projects. For each of those projects, you then need to configure the application code and determine which dependencies are included in your app and the repositories those deps come from. So the repositories
block inside buildscript
is used to configure the actual script execution, while the repositories
block in a project’s build.gradle
file is used to configure the application being built by Gradle.Nikolai
03/22/2019, 3:02 AMNikky
03/22/2019, 9:25 AMNikolai
03/25/2019, 3:03 AM