现在maven-3确实放弃了对<uniqueVersion> false </ uniqueVersion>的快照伪像的支持,似乎你真的需要使用带时间戳的SNAPSHOTS.特别是在内部使用maven 3的m2eclipse似乎受其影响,当SNAPSHOTS不是唯一时,更新快照不起作用.
以前将最佳快照设置为uniqueVersion = false 似乎是最佳做法
现在,切换到带时间戳的版本似乎没什么大问题,毕竟它们是由中央nexus存储库管理的,它可以在常规的intervalls中删除旧的快照.
问题是本地开发人员工作站.他们的本地存储库通过独特的快照很快变得非常大.
如何处理这个问题?
现在我看到了以下可能的解决方案:
保持本地存储库填满硬盘空间的最佳方法是什么?
更新:
为了验证beaviour并提供更多信息,我设置了一个小的nexus服务器,构建两个项目(a和b)并尝试:
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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)
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 Code Online (Sandbox Code Playgroud)
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 Code Online (Sandbox Code Playgroud)
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
我还测试了各种其他配置,首先用神器代替nexus - >相同的行为.然后使用linux maven 3客户端从存储库管理器下载快照 - >本地存储库仍然有时间戳快照:(
HDa*_*ave 34
该<uniqueVersion>
配置应用于已部署(通过mvn deploy)到Maven存储库(如Nexus)的工件.
要从Nexus中删除这些内容,您可以轻松创建自动作业,以便每天清除SNAPSHOT存储库.它可以配置为保留一定数量的shapshots或保持一段时间.它超级简单,效果很好.
开发人员机器上的本地存储库中的工件从"安装"目标到达那里并且不使用这些时间戳...他们只是一直替换SNAPSHOT版本,除非您也在增加修订版本号(例如1.0.0- SNAPSHOT到1.0.1-SNAPSHOT).
小智 13
此插件从本地存储库中删除项目的工件.仅用于保留大型本地快照的一个副本很有用.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>remove-old-artifacts</id>
<phase>package</phase>
<goals>
<goal>remove-project-artifact</goal>
</goals>
<configuration>
<removeAll>true</removeAll><!-- When true, remove all built artifacts including all versions. When false, remove all built artifacts of this project version -->
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
小智 7
好吧,我不喜欢任何提议的解决方案.删除maven缓存通常会显着增加网络流量并减慢构建过程.建立辅助性Maven的插件有助于只有一个神器,我想解决方案,可以清除从本地缓存中的所有过时的时间戳快照文物在一个简单的命令.经过几天的搜索,我放弃了,决定写小程序.最终的计划似乎在我们的环境中运作良好.所以我决定与可能需要这种工具的其他人分享.来源可以从GitHub拉:https://github.com/nadestin/tools/tree/master/MavenCacheCleanup