如何从 CLI(不在项目目录中)下载 Maven 工件及其依赖项的 Java 源代码?
注意:由于下面指定的原因,maven-dependency-plugin 不适合这里
我正在将项目部署到 Artifactory 并附加源。我希望能够运行命令来下载和解压给定工件及其依赖项的源代码。我将使用它来区分工件的两个版本。
我想做的基本上是这样的:
mvn extract:sources -DgroupId=[groupId] -DartifactId=[artifactId] -Dversion=[version]
尝试将 maven-dependency-plugin 中的几个目标结合起来,但这似乎无法满足我的需要:
- :unpack-dependency 需要项目
- :get 要求我显式指定远程存储库。为什么它不能使用我的settings.xml 中的那些?
我尝试编写自己的 mojo 来执行此操作,但很困惑,因为除非我位于项目目录中,否则我似乎无法处理远程存储库。因此我无法下载该项目。即使我下载了该项目,mojo 也已经初始化了它的 ${project},因此我将无法获取它的依赖项等,
非常感谢您的帮助。
Note: maven-dependency-plugin isn't suitable here for reasons specified below
I'm deploying projects to Artifactory with sources attached. I'd like to be able to run a command to download and unpack sources for a given artifact and its dependencies. I'll be using this to diff two versions of an artifact.
What I'd like to do is basically this:
mvn extract:sources -DgroupId=[groupId] -DartifactId=[artifactId] -Dversion=[version]
Have tried combining a couple of goals from the maven-dependency-plugin but this doesn't seem capable of doing what I need:
- :unpack-dependencies requires a project
- :get requires me to explicitly specify a remote repo. Why can't it use those in my settings.xml?
I've tried writing my own mojo to do this but am flummoxed because I can't seem to get a handle on remote repositories unless I'm in a project directory. Thus I can't download the project. And even once I have downloaded the project, the mojo will have already initialised its ${project} hence I won't be able to get its dependencies etc
Would appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
apache ivy jar 可以作为 CLI 程序 来下载Maven 工件。
以下示例从 Maven Central 下载 ivy,然后使用它下载 commons-lang 源 jar:
The apache ivy jar can be used as a CLI program to download Maven artifacts.
The following example downloads ivy from Maven Central, then uses it to download the commons-lang source jar:
我发现最好的方法是使用 3 个 Maven 命令:
这是一个 bash 片段:
The best I found was to use 3 maven commands:
Here is a bash snippet: