你如何有效地处理maven-3时间戳快照? [英] How do you deal with maven-3 timestamped snapshots efficiently?

查看:485
本文介绍了你如何有效地处理maven-3时间戳快照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,maven-3确实 drop支持< uniqueVersion> false< / uniqueVersion>对于快照伪像,您似乎确实需要使用带时间戳的SNAPSHOTS。特别是在内部使用maven 3的m2eclipse似乎受其影响,当SNAPSHOTS不是唯一时,更新快照不起作用。



它似乎最好之前练习将所有快照设置为uniqueVersion = false



现在,切换到带时间戳的版本似乎没什么大问题,毕竟它们是由中央nexus存储库管理的,它可以在常规的intervalls中删除旧的快照。



问题在于本地开发人员工作站。他们的本地存储库很快就可以通过独特的快照实现非常大。



如何处理这个问题?



现在我看到了以下可能的解决方案:




  • 要求开发人员定期清除存储库(导致大量的fustration,因为它需要很长时间才能删除,甚至更长时间才能下载所需的所有内容。)

  • 设置一些脚本,它会删除所有 SNAPSHOT 目录本地存储库并要求开发人员不时运行该脚本(优于第一个,但仍需要相当长的时间来运行和下载当前快照)

  • 使用依赖项:purge-local -repository插件(从eclipse运行时有问题,由于打开文件,需要从每个项目运行)

  • 在每个工作站上设置nexus并设置一个工作来清理旧的快照(最好的结果,但我不想维护50多个nexus服务器,外加内存开发人员工作站紧张的方式)

  • 完全停止使用SNAPSHOTS



什么是最好的方式保持本地存储库不会占用硬盘空间?



更新:



验证beaviour和提供更多信息我设置一个小的nexus服务器,建立两个项目(a和b)并尝试:



a:

 < project xmlns =http://maven.apache.org/POM/4.0.0xmlns:xsi =http://www.w3.org/ 2001 / XMLSchema-instancexsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"> 
< modelVersion> 4.0.0< / modelVersion>
< groupId> de.glauche< / groupId>
< artifactId> a< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< distributionManagement>
< snapshotRepository>
< id> nexus< / id>
< name> nexus< / name>
< url> http:// server:8081 / nexus / content / repositories / snapshots< / url>
< / snapshotRepository>
< / distributionManagement>

< / project>

b:

 < project xmlns =http://maven.apache.org/POM/4.0.0xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi: schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"> 
< modelVersion> 4.0.0< / modelVersion>
< groupId> de.glauche< / groupId>
< artifactId> b< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< distributionManagement>
< snapshotRepository>
< id> nexus< / id>
< name> nexus< / name>
< url> http:// server:8081 / nexus / content / repositories / snapshots /< / url>
< / snapshotRepository>
< / distributionManagement>
< repositories>
< repository>
< id> nexus< / id>
< name> nexus< / name>
< snapshots>
< enabled> true< / enabled>
< / snapshots>
< url> http:// server:8081 / nexus / content / repositories / snapshots /< / url>
< / repository>
< / repositories>
< dependencies>
< dependency>
< groupId> de.glauche< / groupId>
< artifactId> a< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< / dependency>
< / dependencies>
< / project>

现在,当我使用maven并在a上运行deploy时,我将拥有

  a-0.0.1-SNAPSHOT.jar 
a-0.0.1-20101204.150527-6.jar
a-0.0.1-SNAPSHOT.pom
a-0.0.1-20101204.150527-6.pom

在本地存储库中。每次运行部署目标时都会使用新的时间戳版本。当我尝试从nexus服务器更新快照时,也会发生同样的情况(关闭a项目,从本地存储库删除它,构建b)



在一个环境中大量的快照得到构建(想想哈德森服务器...),本地的reposioty充满旧版本



更新2 :



为了测试失败的原因和原因,我做了一些测试。每个测试都针对干净的一切运行(de / glauche从两台机器和连接中删除)




  • mvn使用maven 2.2.1部署:



机器A上的本地存储库确实包含snapshot.jar + snapshot-timestamp.jar



但是:在nexus中只有一个带时间戳的jar,元数据读取:

 <?xml version =1.0encoding = UTF-8 >?; 
< metadata>
< groupId> de.glauche< / groupId>
< artifactId> a< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< versioning>
< snapshot>
< timestamp> 20101206.200039< / timestamp>

< buildNumber> 1< / buildNumber>
< / snapshot>
< lastUpdated> 20101206200039< / lastUpdated>
< / versioning>
< / metadata>




  • 在m2eclipse中运行更新依赖项(在机器B上)(嵌入式m3 final) ) - >本地存储库有snapshot.jar + snapshot-timestamp.jar :(

  • 使用外部maven 2.2.1运行包目标 - >本地存储库有snapshot.jar + snapshot-timestamp。 jar:(



好的,接下来尝试使用maven 3.0.1(删除项目的所有痕迹后)




  • 机器A上的本地存储库看起来更好,只有一个非带时间戳的jar


  • 在nexus中只有一个带时间戳的jar,元数据读取:






    de.glauche
    a
    0.0.1-SNAPSHOT

     < snapshot> 
    < timestamp> 20101206.201808< / timestamp> ;
    < buildNumber> 3< / buildNumber>
    < / snapshot>
    < lastUpdated> 20101206201808< / lastUpdated>
    < snapshotVersions>
    < snapshotVersion>
    < extension> jar< /延伸>
    < value> 0.0.1-20101206.201808-3< / value>
    < updated> 20101206201808< / updated>
    < / snapshotVersion>
    < snapshotVersion>
    < extension> pom< / extension>
    < value> 0.0.1-20101206.201808-3< / value>
    < updated> 20101206201808< / updated>
    < / snapshotVersion>
    < / snapshotVersions>



  • 在m2eclipse中运行更新依赖项(在机器B上)(嵌入式m3 final) - >本地存储库有snapshot.jar + snapshot-timestamp.jar :(


  • 使用外部maven 2.2.1运行包目标 - >本地存储库具有snapshot.jar + snapshot-timestamp.jar :(




<回顾一下:maven3中的部署目标比2.2.1更好,创建机器上的本地存储库看起来很好。
但是,接收器总是有很多时间戳版本。 。



我做错了什么?



更新3



我还测试了各种其他配置,首先用神器替换nexus - >相同的行为。然后使用linux maven 3客户端从存储库管理器下载快照 - >本地存储库仍然有时间戳快照:(

解决方案

< uniqueVersion> 应用于部署(通过mvn部署)到Maven存储库(如Nexus)的工件的配置。



要从Nexus中删除这些内容,您可以轻松创建自动作业,以便每天清除SNAPSHOT存储库。它可以配置为保留一定数量的shapshots或保持一段时间。它非常简单,效果很好。



开发人员机器上本地存储库中的工件从安装目标到达,不要使用这些时间戳...他们只是除非你也在增加版本号(例如1.0.0-SNAPSHOT到1.0.1-SNAPSHOT),否则不断更换一个SNAPSHOT版本。


Now that maven-3 did drop support for the <uniqueVersion>false</uniqueVersion> for snapshot artefacts it seems that you really need to use timestamped SNAPSHOTS. Especially m2eclipse, which does use maven 3 internally seems to be affected with it, update-snapshots does not work when the SNAPSHOTS are not unique.

It seemed best practice before to set all snapshots to uniqueVersion=false

Now, it seems no big problem to switch to the timestamped version, after all they are managed by a central nexus repository, which is able to delete old snapshots in regular intervalls.

The problem are the local developer workstations. Their local repository quickly does grow very large with unique snapshots.

How to deal with this problem ?

Right now i see the folowing possible solutions:

  • Ask the developers to purge the repository in regular intervals (which leads to lots of fustration, as it takes long time to delete and even longer to download everything needed)
  • Set up some script which does delete all SNAPSHOT directories from the local repository and ask developers to run that script from time to time (better than the first, but still takes quite some time to run and download current snapshots)
  • use the dependency:purge-local-repository plugin (Does have problems when run from eclipse, due to open files, needs to be run from each project)
  • set up nexus on every workstation and set up a job to clean old snapshots (best result, but I don't want to maintain 50+ nexus servers, plus memory is always tight on developer workstations)
  • stop using SNAPSHOTS at all

What is the best way to keep your local repository from filling up your hard drive space ?

Update:

To verify the beaviour and to give more info i setup a small nexus server, build two projects (a and b) and try:

a:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>de.glauche</groupId>
  <artifactId>a</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <distributionManagement>
    <snapshotRepository>
        <id>nexus</id>
        <name>nexus</name>
        <url>http://server:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
  </distributionManagement>

</project>

b:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>de.glauche</groupId>
  <artifactId>b</artifactId>
  <version>0.0.1-SNAPSHOT</version>
    <distributionManagement>
    <snapshotRepository>
        <id>nexus</id>
        <name>nexus</name>
        <url>http://server:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
  </distributionManagement>
 <repositories>
    <repository>
        <id>nexus</id>
        <name>nexus</name>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <url>http://server:8081/nexus/content/repositories/snapshots/</url>
    </repository>
 </repositories>
  <dependencies>
    <dependency>
        <groupId>de.glauche</groupId>
        <artifactId>a</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
</project>

Now, when i use maven and run "deploy" on "a", i'll have

a-0.0.1-SNAPSHOT.jar
a-0.0.1-20101204.150527-6.jar
a-0.0.1-SNAPSHOT.pom
a-0.0.1-20101204.150527-6.pom

in the local repository. With a new timestamp version each time i run the deploy target. The same happens when i try to update Snapshots from the nexus server (close "a" Project, delete it from local repository, build "b")

In an environment where lots of snapshots get build (think hudson server ...), the local reposioty fills up with old versions fast

Update 2:

To test how and why this is failing i did some more tests. Each test is run against clean everything (de/glauche gets delete from both machines and nexus)

  • mvn deploy with maven 2.2.1 :

local repository on machine A does contain snapshot.jar + snapshot-timestamp.jar

BUT: only one timestamped jar in nexus, metadata reads:

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>de.glauche</groupId>
  <artifactId>a</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <versioning>
    <snapshot>
      <timestamp>20101206.200039</timestamp>

      <buildNumber>1</buildNumber>
    </snapshot>
    <lastUpdated>20101206200039</lastUpdated>
  </versioning>
</metadata>

  • run update dependencies (on machine B) in m2eclipse (embedded m3 final) -> local repository has snapshot.jar + snapshot-timestamp.jar :(
  • run package goal with external maven 2.2.1 -> local repository has snapshot.jar + snapshot-timestamp.jar :(

Ok, next try with maven 3.0.1 (after removing all traces of project a)

  • local repository on machine A looks better, only one one non-timestamped jar

  • only one timestamped jar in nexus, metadata reads:

    de.glauche a 0.0.1-SNAPSHOT

    <snapshot>
      <timestamp>20101206.201808</timestamp>
      <buildNumber>3</buildNumber>
    </snapshot>
    <lastUpdated>20101206201808</lastUpdated>
    <snapshotVersions>
      <snapshotVersion>
        <extension>jar</extension>
        <value>0.0.1-20101206.201808-3</value>
        <updated>20101206201808</updated>
      </snapshotVersion>
      <snapshotVersion>
        <extension>pom</extension>
        <value>0.0.1-20101206.201808-3</value>
        <updated>20101206201808</updated>
      </snapshotVersion>
    </snapshotVersions>
    

  • run update dependencies (on machine B) in m2eclipse (embedded m3 final) -> local repository has snapshot.jar + snapshot-timestamp.jar :(

  • run package goal with external maven 2.2.1 -> local repository has snapshot.jar + snapshot-timestamp.jar :(

So, to recap: The "deploy" goal in maven3 works better than in 2.2.1, the local repository on the creating machine looks fine. But, the receiver always ends up with lots of timestamed versions ...

What am i doing wrong ?

Update 3

I also did test various other configurations, first replace nexus with artifactory -> same behaviour. Then use linux maven 3 clients to download the snapshots from the repository manager -> local repository still has timestamped snapshots :(

解决方案

The <uniqueVersion> configuration applied to artifacts that were deployed (via mvn deploy) to a Maven repository such as Nexus.

To remove these from Nexus, you can easily create an automated job to purge the SNAPSHOT repository every day. It can be configured to retain a certain number of shapshots or keep them for a certain period of time. Its super easy and works great.

Artifacts in the local repository on a developer machine get there from the "install" goal and do not use these timestamps...they just keep replacing the one and only SNAPSHOT version unless you are also incrementing the revision number (e.g. 1.0.0-SNAPSHOT to 1.0.1-SNAPSHOT).

这篇关于你如何有效地处理maven-3时间戳快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆