Does n't gradle have its own repository in the way Maven has m2?

Viewed 67

Gradle always seems to use maven m2 repository. Does n't it have an equivalent of m2?

1 Answers

Gradle can consume dependencies in different layouts, including Maven, Ivy, Flat directory structures and absolute file locations. So it doesn't always use a Maven repository as you say.

When it downloads external dependencies, it caches them in $HOME/.gradle/caches/modules-2. This is partly what the .m2 is about, but the Gradle one is just a cache and things will be wiped from it after having been unused for a while.

You are also not supposed to use the Gradle cache directory as a local repository for sharing SNAPSHOT versions between projects during development, like you would with .m2. If you need to to this, Gradle can work with a local .m2 repository. Just declare:

repositories {
  mavenLocal()
}

And you can consume and publish artifacts to the local .m2 folder, just like Maven would do.

There are also other ways to produce and consume local artifacts in Gradle, including multi-projects and composite builds, that are sometimes better suited than going through the .m2 repository.

Related