# mavenLocal() not working

**URL:** <https://discuss.gradle.org/t/mavenlocal-not-working/2348>\
**Category:** Old Forum Archive\
**Created:** [January 27, 2015, 8:45pm UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348 "2015-01-27T20:45:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando\_Federico](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@Fernando\_Federico](https://discuss.gradle.org/u/Fernando_Federico)\
**Post date:** [January 27, 2015, 8:45pm UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/1 "2015-01-27T20:45:00Z")

</div>

I have really big issues with the mavenLocal(). If I leave the mavenLocal() as the first repository in my init.gradle (I configured all the company repos in an init file) I don’t get the latests snapshots published in the remote repos. If I put it last I don’t get the changes of the snapshots in my local.

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [January 28, 2015, 12:01am UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/2 "2015-01-28T00:01:00Z")

</div>

Quite simply, this is as designed. Gradle searches through your repositories and returns the first artifact it can find (unless using a dynamic version). This is primarily for performance reasons. I understand this is not the same as how Maven resolves snapshot dependencies, however, I have heard complaints about Maven’s method as well.

I assume that if you have the need to both rely on the latest local or remote artifact (depending on whichever is newer) then you are in fact building that artifact locally. The only workaround I can think of is to simply keep ‘mavenLocal()’ listed first and rebuild locally when there are new remote changes.

---

<div class="post-metadata">

**Author:** ![Fernando\_Federico](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@Fernando\_Federico](https://discuss.gradle.org/u/Fernando_Federico)\
**Post date:** [January 28, 2015, 12:19am UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/3 "2015-01-28T00:19:00Z")

</div>

Thanks for the quick reply!. what if I define the SNAPSHOT dependencies as changing modules with a low caching timeout. would that work?, no matter the location of the mavenLocal()?

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [January 28, 2015, 12:22am UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/4 "2015-01-28T00:22:00Z")

</div>

Unfortunately, no. By default Gradle simply checks for new versions of a changing module every 24 hours. You can tweak that via a resolution strategy but that will not affect Gradle’s behavior in regards to which repository Gradle will resolve the dependency from.

---

<div class="post-metadata">

**Author:** ![Fernando\_Federico](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@Fernando\_Federico](https://discuss.gradle.org/u/Fernando_Federico)\
**Post date:** [January 28, 2015, 12:34am UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/5 "2015-01-28T00:34:00Z")

</div>

So, let me explain my building situation.

My build downloads binaries from Maven and executes those binaries as part of a test suite. The test suite dependes on a shared util library (also deployed with maven).

So If one developer wants to change that library (in his local) and validate the test suite, he needs to change the grade.init and put the mavenLocal() as the first repo, just to bring his change in the util library, leading to the situation that if by any mean he compiled one of the binaries in the past he will be testing those binaries instead of the latest ones?

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [January 28, 2015, 12:41am UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/6 "2015-01-28T00:41:00Z")

</div>

Basically, yes, at least until the version changes. One thing you might consider is perhaps adding some kind of property to your build, whose value will conditionally add ‘mavenLocal()’. This would at least alleviate having to modify your build script when testing local changes. For example:

repositories {

if (project.hasProperty(‘useMavenLocal’)) {

mavenLocal()

}

}

This would then allow a developer to do:

./gradlew -PuseMavenLocal test

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [January 28, 2015, 12:42am UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/7 "2015-01-28T00:42:00Z")

</div>

I’ll add, I tend to recommend conditionally adding ‘mavenLocal()’, at very least in your CI environment. For example, if your CI machines run both Gradle and Maven builds, you could run into these very same issues.

---

<div class="post-metadata">

**Author:** ![Fernando\_Federico](https://avatars.discourse-cdn.com/v4/letter/f/d6d6ee/32.png) [@Fernando\_Federico](https://discuss.gradle.org/u/Fernando_Federico)\
**Post date:** [January 28, 2015, 12:44am UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/8 "2015-01-28T00:44:00Z")

</div>

Thanks!, I can implement something like that.

I would recommend to consider this scenario as part of a “new feature”, I found it a very common scenario among the builds I create.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [January 28, 2015, 12:53am UTC](https://discuss.gradle.org/t/mavenlocal-not-working/2348/9 "2015-01-28T00:53:00Z")

</div>

On the roadmap is the ability to conditionally declare a dependency as either a external module dependency or a project dependency. I believe this would effectively satisfy this use case. Instead of rebuilding a project and publishing to Maven local, you would simply conditionally declare the dependency as a project dependency in the dependent project. This would additionally allow you to benefit from Gradle’s incremental build support.
