Delete artifacts and their entire directory from maven local repository

时间:2015-06-30 14:00:27

标签: maven repository artifacts purge

I am trying to delete old artifacts and the directory they live in from my .m2/repository directory. For example I have several versions of projectA: 4.7.0.222, 4.7.0.223, 4.7.0.224 etc. I only need to keep 4.7.0.224 project since it is the latest build.

How can I remove the older 2 versions 4.7.0.222 and 4.7.0.223 without manually deleting them? I have tried this command:

mvn dependency:purge-local-repository -DreResolve=false -DactTransitively=false -Dverbose=true 

When I was in those project directories, everything was successful, but the items still remained. Does maven have any commands that are similar to a full linux "rm -rf" or No?

1 个答案:

答案 0 :(得分:1)

https://maven.apache.org/plugins/maven-dependency-plugin/usage.html#The_dependency:purge-local-repository_mojo

<强>依赖性:吹扫本地存储库

  

[...]

     

此目标旨在从本地存储库中删除当前项目(或多个模块构建的项目)的所有依赖项

     

[...]

https://maven.apache.org/plugins/maven-dependency-plugin/examples/purging-local-repository.html#Other_purge_configuration

  

[...]

     

要清除所有给定 groupId 的依赖关系,请使用resolutionFuzziness配置参数。

     

如果既未指定include也未指定exlude,则清除当前项目的所有依赖项。

     

[...]

     
      
  • 文件 - 只删除工件的文件。
  •   
  • 版本 - 删除包含此工件的版本目录。
  •   
  • artifactId - 删除包含此工件的artifactId目录。
  •   
  • groupId - 删除包含此工件的groupId目录结构。
  •   
     

要添加不删除 [...] 工件的限制,请将exclude参数添加为逗号分隔的groupId:artifactId对列表。