What does purge-local-repository actually purge?

扶醉桌前 提交于 2020-01-01 08:50:31

问题


I am running the following command from within a maven project directory:

mvn dependency:purge-local-repository

What is the expected behavior?

Will it delete (and re-download?) all the dependencies already existing in my local repo for that particular project (i.e. whose directory I am in) or will it delete all the contents of my local repo?


回答1:


By default, purge-local-repository will remove from the local repository all the files associated to the version of each dependency (including transitive) of the project it is ran on:

Remove the project dependencies from the local repository, and optionally re-resolve them.

The several factors coming into play are:

  • Transitive dependencies are purged by the plugin by default; this is configurable through the actTransitively parameter.
  • All of the purged artifacts from the local repository are re-resolved by default; this is configurable through the reResolve parameter.
  • The actual files that are purged from the local repository correspond to all the files associated to the version of the purged artifact. For example, if the dependency foo:bar:1.0 is purged, all the files under the path foo/bar/1.0/* will be removed. This is configurable through the resolutionFuzziness parameter (whose default value is version):
    • A value of artifactId would purge all the files under the path to artifact id of the artifact being purged. In the example above, all files under foo/bar/** would be purged (so, all versions are removed).
    • A value of groupId would purge all the files under the path to group id of the artifact being purged. In the example above, all files under foo/** would be purged (so, all versions for all artifact ids are removed).
    • A value of file would only purge the file for the artifact being purged. In the example above, only the files bar-1.0.jar* will be removed (this includes any sha1 they could have). It would not purge the associated POM file.

You can see which artifacts are going to be purged by printing the list of all dependencies for the project with the list goal:

mvn dependency:list

optionally adding excludeTransitive to this command, if you decide not to purge transitive dependencies.




回答2:


Following

http://maven.apache.org/plugins/maven-dependency-plugin/purge-local-repository-mojo.html

we that

dependency:purge-local-repository

removes the project dependencies from the local repository, and optionally re-resolve them.




回答3:


Using same purge but in details, If project A and project B (Jar) build on local and Project A depends on B (which is in local Repo) can be resolved like

mvn dependency:purge-local-repository -Dinclude=com.xxxx.projectB:projectB

and add the dependency in Project A will resolve the issue.

<dependency>
                <groupId>com.xxxx.projectB</groupId>
                <artifactId>projectB</artifactId>
                <version>${project.version}</version>
            </dependency>

Hope this helps,



来源:https://stackoverflow.com/questions/40381906/what-does-purge-local-repository-actually-purge

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