问题描述
我想知道是否可以导出/复制使用 Maven 管理的项目的依赖项,同时保持本地存储库中采用的文件夹结构.
I'm trying to know whether it's possible to export/copy dependencies of a project managed using Maven while maintaining the folder structure that is adopted in the local repository.
我需要的根源是我在本地存储库(~8GB)中积累了近十年的大量工件.我不再处理以前任务中那些吸引了大部分工件的旧项目,现在,我需要将单个项目(约 650MB 工件)所需的内容移动到另一台计算机上.我不能只是设置另一台计算机再次下载工件,因为在以前的任务中,许多工件是从本地 Nexus 代理中检索到的.此外,我没有这些工件的源代码,所以我不能安装它们.
The root of my need is that I have amassed through almost ten years a lot of artifacts in my local repository (~8GB). I am no longer working on those old projects from previous assignments that drew most of the artifacts in and now, I need to move just what is needed for one single project (~650MB of artifacts) to a different computer. I can't just set the other computer to download artifacts again because many of these artifacts were retrieved from a local Nexus proxy in previous assignments. Moreover, I don't have the source code for these artifacts so I can't just install them.
dependency:copy-dependencies
没有用,因为所有的工件都被简单地转储到一个文件夹中,而不是说 .m2\repository\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar
dependency:copy-dependencies
doesn't do the trick because all artifacts are simply dumped in a single folder, instead of having say .m2\repository\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar
我相信我的问题也可以改写为如何从本地 Maven 存储库中提取仅与一个特定项目相关的存储库子集?"
I believe my question can also be rephrased as "How can I extract from my local Maven repository a subset of the repository that is related to only one specific project?"
推荐答案
你实际上可以使用 Maven Dependency Plugin 及其 copy-dependencies
目标,正如您所提到的.
You can actually use the Maven Dependency Plugin and its copy-dependencies
goal, as you mentioned.
你实际上错过的是它的 useRepositoryLayout
选项
What you actually missed is its useRepositoryLayout
option
将每个工件放在与默认存储库相同的目录布局中.
例如:/outputDirectory/junit/junit/3.8.1/junit-3.8.1.jar.
- 类型:布尔值.
- 自:2.0-alpha-2.
- 必填:否.
- 用户属性:mdep.useRepositoryLayout.
- 默认:假.
- Type: boolean.
- Since: 2.0-alpha-2.
- Required: No.
- User Property: mdep.useRepositoryLayout.
- Default: false.
因此,您可以执行 - 例如 - 以下内容:
You could hence execute - as an example - the following:
mvn dependency:copy-dependencies -Dmdep.useRepositoryLayout=true \
-DoutputDirectory=.m2/repository
这篇关于导出 Maven 依赖项并维护存储库文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!