Export Maven dependencies and maintain repository folder structure

橙三吉。 提交于 2021-02-20 19:15:39

问题


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.

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 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

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?”


回答1:


You can actually use the Maven Dependency Plugin and its copy-dependencies goal, as you mentioned.

What you actually missed is its useRepositoryLayout option

Place each artifact in the same directory layout as a default repository.
example: /outputDirectory/junit/junit/3.8.1/junit-3.8.1.jar.

  • 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



回答2:


If you missing some dependency, then download that dependencies from other source and paste it in your .m2(maven local repository ) folder.



来源:https://stackoverflow.com/questions/35999109/export-maven-dependencies-and-maintain-repository-folder-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!