when I am doing development I often need to change a dependency, but I'm not ready to deploy my changes. For example, I'm working on project Foo and I realize I need to add a method to the common library. Before deploying this change to our internal repository, I would like to install the changes to common library (mvn install
) and recompile Foo to use the common library in the local repository (note that I'm using all SNAPSHOT versions).
However, after I mvn install
my common library, when I recompile Foo it doesn't use the new common library--it keeps using the latest SNAPSHOT of common library in the internal repository. If I deploy the changed common library, Foo picks it up immediately.
How can I get maven to look first in the local repository?
UPDATE: when the file is installed into the local repository, it gets a name like foo-1.0.0-SNAPSHOT.jar
, but when I deploy it, it gets a timestamp foo-1.0.0-20111104.191316-23.jar
. I think this is why the remote artifact gets pulled each time. Any idea why mvn install
is not working like mvn deploy
? Does it have to do with the fact that I have a snapshot repository set up for deploy?
In maven we can define 0 or more repositories where it looks for resources. Repositories can be defined in settings. xml or within your pom. By default if you define no repositories everything will come from a repository name 'central' which is just the default one maintained by maven.
Changing the Location of Local RepositoryNavigate to path {M2_HOME}\conf\ where M2_HOME is maven installation folder. Open file settings. xml in edit mode in some text editor. Update the desired path in value of this tag.
By default, maven local repository is %USER_HOME%/. m2 directory. For example: C:\Users\SSS IT\. m2.
By default, Maven checks for new versions of SNAPSHOT artifacts once per day. When it does this check, it will download SNAPSHOTS from remote repos that are newer than what you have locally. Either your artifact timestamps are out of sync and you're doing something to override Maven's update policy (like calling it with -U or setting the udpatePolicy to "always"), or else the local repository you're installing the artifact to isn't the same one you're subsequently running Maven against. What you're describing isn't typical Maven behavior. For a better answer, give more details in your question.
One indicator you can look for: after you install your common artifact, when you next compile Foo, does Maven download the common artifact again? If so, then it really is getting it from the remote, and you need to check your update settings. If not, then you have something strange going on locally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With