https://kotlinlang.org logo
#announcements
Title
# announcements
n

Nikolai

07/15/2019, 4:34 PM
Hi, everyone I am continuing to learn gradle things. If I create an multiplatform project in Idea it will have two build.gradle files inside. One is the root with following content :
Copy code
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
    }
}
repositories {
    google()
    jcenter()
}
Why we need repositories here? According to docs it configure repositories for current project. But this is the root file. And it have repositories inside buildscript. This repositories didn't count for subprojects (whats why child build.script have it's own repositories closure). If I remove it - nothing changes, app still build and run (at least on Android). In Android studio this closure looks like :
Copy code
allprojects {
  repositories {
      google()
      jcenter()
  }
}
Which is quite understandable. Maybe I am missing something and this repository closure have some purpose?
c

Casey Brooks

07/15/2019, 4:41 PM
You’re right, the
repositories
block in the root project is unnecessary, since the root project isn’t doing anything for itself other than setting up the buildscript. If you put the
repositories
block inside the
allprojects
as in your second snippet, then it will be applied to all projects in your build, and you do not need to declare the
repositories
in each project’s
build.gradle
file.
n

Nikolai

07/15/2019, 4:50 PM
@Casey Brooks Thanks
2 Views