Download dependencies to local repository but not to “target” one

走远了吗. 提交于 2019-12-24 15:58:48

问题


I have a project, that has pom.xml and depends on lots of dependencies from outside (located far-far in internet..).

So, I want to download all those dependencies which I depend on to my "local repository".

This is my try (I do not need do compilation, so I use "validate" here. So I'm do not expect to have "target" folder in the end):

mvn validate -Dmaven.repo.local=C:\my\.m2\repository dependency:copy-dependencies 

In the end - yes I have many dependencies been downloaded to "C:\my\.m2\repository", but some of them went to: C:\projects\myProject\java\trunk\target\dependency, like these ones:

junit-4.8.1.jar
log4j-1.2.8.jar
mockito-all-1.8.2.jar

Question is: how to make those to be downloaded to "C:\my\.m2\repository" but not to "target" of my project?

For now, because of that, another projects that depend on that are failing while building, because they are expecting to find "junit-4.8.1.jar" in local repo.

Another try:

mvn validate -Dmaven.repo.local=C:\my\.m2\repository dependency:resolve

Then those dependencies are not resolvable at all.

Could not resolve dependencies for project bla-bla-SNAPSHOT: The following artifacts could not be resolved: commons-lang:commons-lang:jar:2.4, log4j:log4j:jar:1.2.8, junit:junit:jar:4.8.1: Could not find artifact commons-lang:commons-lang:jar:2.4 -> [Help 1]


回答1:


Maven did that because you invoked the goal dependency:copy-dependencies. It will copy the dependencies of the current module to

 ${project.build.directory}/dependency

See http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html

I really can't imagine these dependencies did not get into your local repo. Fiddling around with a script may not be the solution to your problem. Try

 mvn process-resources -U -Dmaven.repo.local=C:\my\.m2\repository

The -U option forces a download of all dependencies. I suggest using process-resources, although as of my understanding validate should be fine, too.



来源:https://stackoverflow.com/questions/18153611/download-dependencies-to-local-repository-but-not-to-target-one

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