在构建机器上清除Maven本地存储库

在构建机器上清除Maven本地存储库

本文介绍了在构建机器上清除Maven本地存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CI构建服务器上,本地Maven存储库重复填充文件系统(几天后)。
在这种情况下,其他人在修剪本地存储库的策略是什么?
-Max

On a CI build server, the local Maven repository fills up the file system repetitively (after a few days).What strategy are others doing to trim the local repository in such a case?-Max

推荐答案

Maven依赖插件有一个目标,允许您从

The Maven dependency plugin has a purge-local-repository goal that allows you to delete the dependencies for a given project from the local repository, if this is run say once a day on each project the snapshots will not accumulate.

或者,还有一个更多的烧焦的方法,你可以采取。由于问题通常是带时间戳的快照工件,因此您可以使用删除与资源集合模式匹配的所有文件。

Alternatively there's a more scorched-earth approach you could take. As the problem is typically the timestamped snapshot artifacts, you could use the maven-antrun-plugin to delete all files that match the resource collection pattern.

例如(注意,这可能需要一些调整,因为我已经从内存中) / p>

For example (note this might need some tweaking as I've done it from memory):

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <phase>package</phase>
      <configuration>
        <tasks>
          <delete>
            <fileset dir="${settings.localRepository}">
              <include name="**/*.jar"/>
              <exclude name="**/*.pom"/>
              <exclude name="**/*.war"/>
              <exclude name="**/*.ear"/>
              <exclude name="**/*.md5"/>
              <exclude name="**/*.sha"/>
              <!--any other extensions?...-->
              <!--match the timestamp pattern-->
              <containsregexp expression="[0-9]{8}.[0-9]{6}-[0-9]+"/>
            </fileset>
          </delete>
        </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

这篇关于在构建机器上清除Maven本地存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:30