Gradle settings.xml file equivalent from Maven to define a global Local Repository

Hello

I am beginner with Gradle. I am a Maven user. I have read some blogs and video tutorials from youtube. I want do a complete migration from Maven to Gradle.

I did a research about the following situation without any results.

If Maven within its directory structure has the settings.xml file, where it lets me define the location of my own local repository directory to anywhere, from where any dependency (already downloaded or to be download in the future) is used for any Maven project.

How I can do the same for Gradle?. I have checked the directory structure and there is no a similar file to accomplish this goal.

I have read some tutorials where it reuses the Maven installation. I don’t want this approach. I want configure it directly from Gradle, without Maven installation in the pc/notebook, and in a global way how Maven does.

Is possible this? If yes, could you share the correct instructions? (Blog, tutorial)

Thanks in advanced.

You could use an init script.

allprojects {
    repositories {
        maven {
            url "https://repo.foo.com/m2"
        }
    }
}

Hello Mark

Again, thanks a lot by your support.

I understand that init script is the equivalent of settings.xml.

From your code just some new questions

One: If with Maven through the settings.xml file I have the following:

<localRepository>/Users/somename/mavenrepository</localRepository>

what could be the equivalent for gradle to for example define the following location:

  • /Users/somename/gradlerepository

Two: that Local Repository is the mavenLocal()?

Three: why your current url value and not mavenCentral()?

Four: I want to know if the following is correct:

if I have the project named gradle-01 with the following build.gradle content about the repository

repositories {
	mavenLocal()
}

I am assuming Gradle tries to get the dependencies already downloaded in my Local Repository (/Users/somename/gradlerepository) defined globally on the init script file and if a dependency is not found in the Local Repository (is new) then Gradle proceed to call the mavenCentral to try to get the dependency from Maven Central.

I want that behaviour how Maven does or offers.

Thanks in advance

Gradle will read this value from the settings.xml so you can continue to store it there. Alternatively you can specify it via the maven.repo.local system property.

Yes.

Just as an example of specifying a Maven repository at a custom location.

Gradle will only try to look in Maven central if mavenCentral() has been explicitly defined in the repositories { } block.

Hello Mark

Thanks again by your valuable explanation.

Gradle will read this value from the settings.xml so you can continue to store it there. Alternatively you can specify it via the maven.repo.local system property.

However, remember I want do this Gradle configuration without a Maven installation in the machine.

Then you’ll want to use the system property approach.

Thanks again Mark

I have decided keep Maven in my machine. It with the intention to be free in create or work with a project based on Maven.

Now thinking in reuse a directory to be used how a shared or common repository for Maven and Gradle, just curious if you can help me here:

Thank You.

1 Like