Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where and why add repositories on build.gradle

When Android Studio creates a project, the top-level build file has two repositories definitions, one inside buildscript and another inside allprojects.

// Top-level build file where you can add configuration options common to all sub-    projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

Where must I add another repository and why?

I think that repository inside buildscript is here to add the gradle plugin dependency, but I'm not sure...

Someone could clarify me, please.

Thank you!

like image 330
SergiBC Avatar asked Apr 15 '14 07:04

SergiBC


People also ask

What is repositories in build Gradle?

Popular public repositories include Maven Central and the Google Android repository. Gradle provides built-in shorthand notations for these widely-used repositories. Under the covers Gradle resolves dependencies from the respective URL of the public repository defined by the shorthand notation.

Where do I put repositories in Android Studio?

Open the project where you want to use your cloned library, then select 'File > New > Import Module' from the Android Studio toolbar. Click the three-dotted button and navigate to your cloned repository. Select this repository, then click 'OK. '

Where should I add dependencies in Gradle project?

Gradle declares dependencies on JAR files inside your project's module_name /libs/ directory (because Gradle reads paths relative to the build.gradle file). This declares a dependency on version 12.3 of the "app-magic" library, inside the "com.example.android" namespace group.


1 Answers

The buildscript is for dependencies of your build files. You want to add a repository there if, for example, a task in your build.gradle needs a plugin that is not found in the standard Gradle distribution, like a gwt wrapper.

The allprojects is for dependencies needed by your application, like log4j, Guice, Guava and so on.

Also, be warned that using mavenCentral for retrieving dependencies is a bit discouraged, because if the network is down or if the project is removed from their repositories, you won't be able to build your project anymore

like image 107
Raffaele Avatar answered Oct 02 '22 05:10

Raffaele