21

It's slow to visit the maven official repositories from my country, so I want to try some local repositories first.

Is it able to add them to some global gradle configuration file, that I can just use them in each gradle project, without modifying the project-scope build.gradle file?

Freewind
  • 193,756
  • 157
  • 432
  • 708

2 Answers2

34

I would suggest to use the init.gradle script which is located in your home folder $HOME/.gradle/init.gradle which might contain the following content:

allprojects {
    repositories {
        mavenLocal()
        maven {
          url "http://localhost:8081/nexus/content/groups/public/"
        }
    }
}
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 1
    Note I also had to add the repositories to a buildscript block like in https://stackoverflow.com/questions/17773817/purpose-of-buildscript-block-in-gradle – khylo Oct 14 '19 at 14:42
  • 1
    "As a general advice, you should avoid adding mavenLocal() as a repository. " https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:case-for-maven-local Please edit your answer. – burtsevyg Feb 18 '21 at 10:26
  • That would work for dependencies only. For plugins different semantics is required: https://github.com/gradle/gradle/issues/9016#issuecomment-483581381 – Johannes Aug 05 '21 at 11:50
5

I guess that what are You looking for are init scripts.

Opal
  • 81,889
  • 28
  • 189
  • 210