java Maven - 如何验证声明的存储库中的依赖项是否可用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10490135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven - How do I validate dependencies are available in the declared repositories?
提问by Marty Pitt
I have just edited the <repositories />
section of my pom.xml
file for a project, removing a couple of repo's I thought were unneeded.
我刚刚为一个项目编辑了<repositories />
我的pom.xml
文件部分,删除了几个我认为不需要的 repo。
I'd like to validate that the declared dependencies are still resolvable in the available repositories.
我想验证声明的依赖项在可用存储库中是否仍可解析。
However, all of the declared dependencies are available in my local repo, so any attempt to build will just use the local ones.
但是,所有声明的依赖项都在我的本地存储库中可用,因此任何构建尝试都将只使用本地的。
I don't want to simply nuke my local repo, as it takes many hours to download all the dependencies from scratch.
我不想简单地破坏我的本地存储库,因为从头开始下载所有依赖项需要很多小时。
Similarly, I'm not interested in having maven attempt to download all the dependencies, I just want it to ensure that they're all resolvable (including transitive dependencies).
同样,我对让 Maven 尝试下载所有依赖项不感兴趣,我只想确保它们都是可解析的(包括传递依赖项)。
How do I do this?
我该怎么做呢?
回答by Hawk
run
mvn dependency:analyze
跑
mvn dependency:analyze
it will check dependencies for you.
它将为您检查依赖项。
ref: http://maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html
参考:http: //maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html
回答by khmarbaise
The first thing i can say is not to define repositories in a pom, cause it will cause many problems in particular for others who are using this project. Furthermore i recommend to use a repository manager which will solve the problem and improve performance during download and will simplify the check of such circumstances which means simply delete the local repo and try to build.
我可以说的第一件事是不要在 pom 中定义存储库,因为它会导致许多问题,特别是对于使用该项目的其他人。此外,我建议使用存储库管理器,它可以解决问题并提高下载过程中的性能,并将简化对此类情况的检查,这意味着只需删除本地存储库并尝试构建。
回答by bmargulies
Empty your local repo (rm -rf ~/.m2/repository) and build.
清空您的本地存储库 (rm -rf ~/.m2/repository) 并构建。
You can't fix the problem of this being time-consuming. There's no way to know if a particular artifact is in a particular external repo without downloading it. If maven just asked 'have you got X?' you'd get false positives from broken artifacts, which are endemic in some repos.
您无法解决这种耗时的问题。如果不下载某个特定的工件,就无法知道某个特定的工件是否在特定的外部存储库中。如果 maven 只是问“你有 X 吗?” 您会从损坏的工件中得到误报,这些工件在某些存储库中很普遍。
回答by Maniganda Prakash
Emptying the local repo seems to be the only option. This link may help prevent maven to resolve dependencies in local repository.
清空本地仓库似乎是唯一的选择。此链接可能有助于防止 maven 解析本地存储库中的依赖项。
回答by carlspring
Well, if you're willing to knock up your own plugin, something that springs to mind would be to have the plugin resolve only the checksums. These checksums are only deployed to the remote repository, after the respective jar/war/zip/whatever artifacts have been already been deployed.
好吧,如果您愿意使用自己的插件,那么您会想到让插件仅解析校验和。这些校验和仅在已部署相应的 jar/war/zip/whatever artifacts 之后才部署到远程存储库。
If it takes hours to download all the artifacts, well, then you clearly need a repository manager such as Nexus, or Artifactory, like Karl-Heinz already suggested. It will keep cached versions of your remote artifacts and downloading from it would be a sort matter of time.
如果下载所有工件需要几个小时,那么您显然需要一个存储库管理器,例如 Nexus 或 Artifactory,就像 Karl-Heinz 已经建议的那样。它将保留您的远程工件的缓存版本,从中下载将是一个时间问题。
回答by Roaders
I assume you have tried mvn validate -U ? I'm no great maven expert but that's what I'd try. (Although I quite regularly blast my local non-third-party report to make absolutely sure the build will work for everyone else).
我假设您已经尝试过 mvn validate -U ?我不是伟大的 Maven 专家,但这就是我要尝试的。(尽管我经常爆破我的本地非第三方报告以绝对确保构建对其他人有用)。
回答by John Tribe
Maybe this is not the answer but for some reason I have html in pom files so sometimes I add Mvn dependency to pom.xml at the begining:
也许这不是答案,但出于某种原因,我在 pom 文件中有 html,所以有时我在开始时将 Mvn 依赖项添加到 pom.xml:
<repositories>
<repository>
<id>mvn</id>
<name>mvn</name>
<url>http://maven.icm.edu.pl/artifactory/repo/</url>
</repository>
...other resps
and remove whole .m2/repositories dir or I search for broken files with :
并删除整个 .m2/repositories 目录,或者我使用以下命令搜索损坏的文件:
grep -R -l -L groupId --include \*.pom //Search all that not contain groupId string
(execute this in .m2 dir)
(在 .m2 目录中执行此操作)