java 用于从没有 mvn/poms 的 maven repo 下载工件的实用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/884808/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:14:15  来源:igfitidea点击:

Utility for downloading artifacts from maven repo without mvn/poms

javamaven-2repositoryaether

提问by whaley

Is there a maven client that isn't mvn (the binary included with the maven distribution) I could use to pull down an artifact from a maven repository without using a pom? I'd like to use a maven repository as the repo for our ops team to pick up builds (including snapshots of builds) but I don't want them to have to mess around with writing poms and declaring dependencies in them. Ideally, I'm looking for just a cli client that I could just pass in a repo url and coordinates and download a given artifact. Does such a thing exist or am I better off writing a one-off script for this?

是否有一个 maven 客户端不是 mvn(maven 发行版中包含的二进制文件),我可以用来从 maven 存储库中提取工件而不使用 pom?我想使用 Maven 存储库作为我们的操作团队的存储库来获取构建(包括构建的快照),但我不希望他们不得不在编写 poms 和声明依赖项时搞砸。理想情况下,我正在寻找一个 cli 客户端,我可以只传递一个 repo url 和坐标并下载给定的工件。是否存在这样的事情,还是我最好为此编写一次性脚本?

采纳答案by Taylor Leese

Use Nexus. It provides a web interface that other teams can use to download artifacts. http://nexus.sonatype.org/

使用 Nexus。它提供了一个 Web 界面,其他团队可以使用它来下载工件。http://nexus.sonatype.org/

回答by Pascal Thivent

I see 3 easy options:

我看到 3 个简单的选项:

  1. Just send them a link pointing on your artifact in your repository and have them use their browser.
  2. Install and use wget(wget http://path/to/artifact.extension).
  3. Install and use mvn dependency:get(requires mvnbut doesn'trequire a pom.xml, see this answerfor more details).
  1. 只需向他们发送指向您存储库中工件的链接,并让他们使用浏览器即可。
  2. 安装和使用wget( wget http://path/to/artifact.extension)。
  3. 安装和使用mvn dependency:get(需要mvn要求pom.xml,看到这个答案详细介绍)。

回答by Jherico

Use the maven embedder. More to the point, use the functionality inside the maven embedder for resolving and downloading jars. Although if you're trying to just write a simple CLI, the repository structure isn't complex and you could easily write a script that takes a maven repo url, artifact ID, group ID and version to generate the full URL to the jar.

使用 Maven 嵌入器。更重要的是,使用 maven 嵌入器中的功能来解析和下载 jar。尽管如果您只想编写一个简单的 CLI,存储库结构并不复杂,您可以轻松编写一个脚本,该脚本采用 maven 存储库 url、工件 ID、组 ID 和版本来生成 jar 的完整 URL。

回答by yegor256

This is how we do it in jcabi-aether:

这就是我们在jcabi-aether中的做法

final File repo = this.session.getLocalRepository().getBasedir();
final Collection<Artifact> deps = new Aether(this.getProject(), repo).resolve(
  new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
  JavaScopes.RUNTIME
);

All you need to provide to this lib is 1) a list of remote repositories, 2) location of a local repo, and 3) Maven coordinates of the artifact. The library uses Apache Aetherfrom Sonatype.

您需要为此库提供的所有内容是 1) 远程存储库列表,2) 本地存储库的位置,以及 3) 工件的 Maven 坐标。该库使用来自 Sonatype 的Apache Aether

回答by matt b

Well technically the repository is accessed over HTTP, so given the repository location, artifact and coordinates, it should just be possible to give your ops team a URL to the artifact that they can hit in any browser.

从技术上讲,存储库是通过 HTTP 访问的,因此鉴于存储库的位置、工件和坐标,应该可以为您的运营团队提供他们可以在任何浏览器中访问的工件的 URL。

回答by Toni Menzel

Think about Pax URLwhich lets you use plain URLs to reference maven artifacts like so:

想想Pax URL,它允许您使用普通 URL 来引用 Maven 工件,如下所示:

mvn:groupId/artifactId/version

See PAX URL Websitefor more info (MVN Protocol Handler).

有关详细信息,请参阅PAX URL 网站(MVN 协议处理程序)。

Toni

托尼