18

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

1 Answer 1

27

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.

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.

1
  • 1
    The documentation has moved
    – Grubshka
    Feb 9, 2022 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.