Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does gradle store in .m2 and when in cache?

Tags:

gradle

In which scenario will gradle store artifacts in the directory .m2 and in which scenario will it store them in gradle\caches?

I am trying to resolve my issue wherein I have a dependency within my local build

like image 536
letthefireflieslive Avatar asked May 06 '18 06:05

letthefireflieslive


People also ask

Where does Gradle store cache?

Gradle caches artifacts in USER_HOME/. gradle folder.

Does Gradle use .m2 directory?

If no settings. xml is available, Gradle uses the default location USER_HOME/. m2/repository . Note, however, that Gradle cautions against using the local Maven repository unless you really need it.

Does Gradle use Maven cache?

Gradle will use its own internal cache for all resolved dependencies, including ones coming from the local maven repository. For example, if you use a dependency org:foo:1.0 from your maven local repository, the metadata and artifact will be copied to the Gradle cache on first resolution.

Does Gradle cache?

Gradle supports a local and a remote build cache that can be configured separately. When both build caches are enabled, Gradle tries to load build outputs from the local build cache first, and then tries the remote build cache if no build outputs are found.


1 Answers

Gradle will read from your local maven repository only when you declare it as a valid repository:

repositories {
    mavenLocal()
}

Gradle will write to your local maven repository only when you publish artifacts and tell it to publish to the local maven repo.

  • If you are using the maven plugin, when executing the task install
  • If you are using the maven-publish plugin, when executing the task publishToMavenLocal

Gradle will use its own internal cache for all resolved dependencies, including ones coming from the local maven repository.

For example, if you use a dependency org:foo:1.0 from your maven local repository, the metadata and artifact will be copied to the Gradle cache on first resolution. From then on, the dependency will be resolved from the Gradle cache.

However, if the dependency is changing, such as when using a -SNAPSHOT version, the Gradle cache will by default keep the last one resolved for 24h. After which it will perform a new resolution, hitting again the local maven repository in this example.

See the documentation for controlling that cache duration for dynamic and/or changing dependencies.

like image 60
Louis Jacomet Avatar answered Oct 19 '22 06:10

Louis Jacomet