Maven:如何检查工件是否存在?
如何从 Mojo 内部检查本地存储库中是否已存在工件?
我正在将大型二进制文件安装到本地 Maven 存储库中,在尝试下载它们之前我需要知道它们是否已经存在。
How do I check from within a Mojo if an artifact already exists in the local repository?
I'm installing large binaries into the local Maven repository and I need to know if they already exist before attempting to download them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 http://docs.codehaus.org/display/MAVENUSER 的帮助下解决/Mojo+Developer+Cookbook
如果您想检查远程工件是否存在而不下载它,您可以使用 Aether 库 执行以下操作(基于 http ://dev.eclipse.org/mhonarc/lists/aether-users/msg00127.html):
具有以下依赖项:
org.eclipse.aether:aether-util:0.9.0.M2 和以下导入:
Solved with the help of http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook
If you want to check if a remote artifact exists without downloading it, you can use the Aether library to do the following (based on http://dev.eclipse.org/mhonarc/lists/aether-users/msg00127.html):
With following dependency:
org.eclipse.aether:aether-util:0.9.0.M2
and following imports:由于被接受为正确的答案不再指向有效的 URL,并且因为我知道更好的方法,所以我发布了一个新答案。
有 wagon-maven-plugin,它有一个
存在
目标。该文档有点不准确,但您可以使用它。就代码而言,您可以查看 DefaultWagonDownload 类'
存在方法:
Since the answer which is accepted as correct, is no longer pointing to valid URL-s and because I know a better way, I am posting a new answer.
There's the wagon-maven-plugin, which has an
exist
goal. The documentation is a bit inaccurate, but you can use that.Code-wise, you can have a look at the DefaultWagonDownload class'
exists
method:如果您希望您的工件存在于远程 Maven 存储库中,我建议您只需使用 复制
maven-dependency-plugin
的魔力。它将使用正常的 Maven 解析机制来检索工件,因此不会下载本地存储库中已有的内容。
在插件中,当使用maven 2(不确定maven3)时,您可以使用 mojo 执行器 来轻松从代码中调用魔力。
If you expect your artifacts being present in a remote maven repository, I'd suggest you simply use the copy mojo of the
maven-dependency-plugin
.It will use normal maven resolution mechanism for retrieving artifacts so will not download something that is already in the local repository.
In a plugin, when using maven 2 (not sure about maven3) you can use the mojo executor to call a mojo from within you code easily.