如何防止Maven解决本地存储库中的依赖关系 [英] How to prevent maven to resolve dependencies in local repository

查看:170
本文介绍了如何防止Maven解决本地存储库中的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以告诉Maven(在执行 mvn软件包 mvn站点或...时)不要解决本地存储库中的依赖项?

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

此问题的背景:有时,当以前存储的依赖项(例如SomeProject-0.7-ALPHA)在远程存储库中不再可用时,我会遇到麻烦.在我的本地版本中,由于依赖项之前已被缓存,所以一切仍然可以正常工作.当我与他人共享pom时,他们可能会遇到麻烦,因为他们没有该依赖项的缓存版本,并且该依赖项无法再从远程存储库中解决.

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!

推荐答案

是否有一种方法可以告诉Maven(在执行mvn软件包,mvn站点或...时)不要解决本地存储库中的依赖项?

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).

有时候,当以前存储的依赖项(例如SomeProject-0.7-ALPHA)在远程存储库中不再可用时,我会遇到问题.

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.

我与他人共享pom时,他们可能会遇到麻烦,因为他们没有该依赖项的缓存版本,并且该依赖项无法再从远程存储库中解决.

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.

一种检查其他项目是否可行的方法是清除要从本地存储库中共享的项目的依赖项,然后重新解析它们.当然,手动执行此操作确实很痛苦,但好消息是 Maven依赖插件为此设置了purge-local-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.

这篇关于如何防止Maven解决本地存储库中的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆