16

Is there a way to tell maven (when doing mvn package, mvn site or ...) not to resolve the dependencies from the local repository?

Background of this question: Sometimes I get into problems, when previously cached dependencies (e.g. SomeProject-0.7-ALPHA) are no longer available in the remote repository. In my local build everything still works fine as the dependency has been cached before. As soon as I share my pom with others, they may get into trouble, as they dont have a cached version of that dependency and the dependency can no longer be resolved from the remote repository.

Any help will be appreciated. Thanks in advance!

4
  • Why is the dependency not available anymore in the remote repo? If there is a newer version, why not simply upgrade to it? If the new version is not backward compatible, why remove the old? Commented May 5, 2010 at 11:07
  • The problem is detecting the fact, that the old version is no longer available. I cant check all dependencies manually and as I am having the local cached version of the no longer available dependency maven wont tell me that there is a problem. Commented May 5, 2010 at 11:12
  • I understand your direct problem; however, I tried to note with my questions that IMHO there may be a process problem behind it. And in this case it is probably better to solve the root cause rather than look for a workaround. Commented May 5, 2010 at 11:19
  • Thanks for the input Péter, as commented on khmarbaise answer, I will have a deeper look on my process. Thanks for your help anyways! Commented May 5, 2010 at 11:49

2 Answers 2

22

Is there a way to tell maven (when doing mvn package, mvn site or ...) not to resolve the dependencies from the local repository?

No, that's how the whole dependency resolution works (via the local repository).

Sometimes I get into problems, when previously cached dependencies (e.g. SomeProject-0.7-ALPHA) are no longer available in the remote repository.

Sorry for stating the obvious but removing dependencies from a remote repository is an horrible practice and leads to... well the kind of troubles you're facing. If possible, avoid doing that.

As soon as I share my pom with others, they may get into trouble, as they dont have a cached version of that dependency and the dependency can no longer be resolved from the remote repository.

One way to check that things would work for others would be to purge the dependencies of the project you're going to share from your local repository and to re-resolve them. Of course, doing this manually would be really painful but the good news is that the Maven Dependency Plugin has a purge-local-repository goal for that.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:purge-local-repository  \
    -DreResolve=true \
    -DactTransitively=true \ 
    -Dverbose=true

If this fails, then you know that something is missing and can't be resolved anymore which is basically what you want to know. But you've also lost it so make a backup of your repository if this matters to you.

3
  • 1
    Accepted, as purge-local-repository is the thing I was looking for. Hope I wont need it in the future anymore. Thanks! Commented May 5, 2010 at 20:18
  • @Nils You're welcome. Feel free to upvote too if you think it makes sense for this accepted answer :) Commented May 5, 2010 at 20:44
  • how about for the plugins the project was using. Is there a purge for the plugins? purge-local-repository clears the dependencies, not the plugins..
    – Sa'ad
    Commented Feb 24, 2012 at 9:17
2

The basic test of a maven build is to delete the local repository .m2/repository and try to build (mvn package) and see if it is working. If not you have other problems here. As mentioned the problem seemed to be the process you are working with. If a dependency is not available anymore from a remote repository there is an other problem. Are you using a Repository Manager for example Nexus, Archiva, Artifactory ?

4
  • I was thinking about deleting/moving the whole local repository as well, in fact that is what I have done in some cases, but this is not so optimal. I am not using a Repository Manager. The repositories I am using are not under my control. I will take your input and thing about my processes first. I thought there might be a flag to switch off the local repository, but I see, that this would just be a workaround... Thanks for your help! Commented May 5, 2010 at 11:48
  • 1
    There is no flag to turn off the usage of the local repository. If you are not using a Repo Manager personally you should thinking about setting up in the company. The only thing what you can do with your local repository is to change the location but that's it.
    – khmarbaise
    Commented May 5, 2010 at 12:20
  • +1 for the suggestion of setting up a company / project repo - I was about to suggest the same :-) Commented May 5, 2010 at 12:51
  • @khmarbaise I'm not really sure how using a repository manager helps. I'm looking at this because my workplace does have a repository manager. In fact we have multiple competing internal groups with competing repository managers... Different projects use different repository managers based on what group created them, when they were created, etc., so it's a regular occurrence that you have some local cache of dependency X downloaded from repository manager A, even though the pom for this project specifies repository manager B which (you will find out later) does not provide dependency X... Commented Nov 19, 2021 at 14:25

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.