Java 如何阻止 Maven/Artifactory 保留带有时间戳的快照

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1243574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 07:22:33  来源:igfitidea点击:

How to stop Maven/Artifactory from keeping Snapshots with timestamps

javamavenmaven-2artifactory

提问by Pablojim

Due to disk space considerations I'd like to only ever keep one version of any snapshot in my repository. Rather than keeping multiple versions with timestamp suffixes

由于磁盘空间的考虑,我只想在我的存储库中保留任何快照的一个版本。而不是保留带有时间戳后缀的多个版本

e.g. ecommerce-2.3-20090806.145007-1.ear

例如 ecommerce-2.3-20090806.145007-1.ear

How can I set this up? Is this a build setting or repository (Artifactory) setting

我该如何设置?这是构建设置还是存储库(Artifactory)设置

Thanks!

谢谢!

采纳答案by Rich Seller

The simplest (and recommended) way is to use non-unique snapshots. If you must use unique snapshots, you can do this in Artifactory by specifying the <maxUniqueSnapshots> property on the <localRepository> definition in artifactory.config.xml

最简单(也是推荐)的方法是使用非唯一快照。如果您必须使用唯一的快照,您可以在 Artifactory 中通过在 artifactory.config.xml 中的 <localRepository> 定义上指定 <maxUniqueSnapshots> 属性来执行此操作

For example:

例如:

<localRepository>
  <key>snapshots</key>
  <blackedOut>false</blackedOut>
  <handleReleases>false</handleReleases>
  <handleSnapshots>true</handleSnapshots>
  <maxUniqueSnapshots>1</maxUniqueSnapshots>
  <includesPattern>**/*</includesPattern>
  <snapshotVersionBehavior>non-unique</snapshotVersionBehavior>
</localRepository>

For reference you can do this in Nexus(via the UI) by setting up a scheduled service, it allows you to specify the minimum number to retain, the maximum period to retain them for, and whether to remove the snapshot if a release version is deployed.

作为参考,您可以通过设置计划服务Nexus(通过 UI)中执行此操作,它允许您指定要保留的最小数量、保留它们的最长时间以及如果发布版本是,是否删除快照部署。

回答by Pablojim

NOTE THAT THIS FEATURE/CAPABILITY HAS BEEN REMOVED IN MAVEN 3.0

请注意,此特性/功能已在 Maven 3.0 中删除

Just add something to my own question:

只需在我自己的问题中添加一些内容:

Adding

添加

<distributionManagement>
    ...
    <snapshotRepository>
        ...
        <uniqueVersion>false</uniqueVersion>
    </snapshotRepository>
    ...
</distributionManagement>

to my parent pomalso contributed to the solution of this.

对我的父母pom也有助于解决这个问题。

See:

看:

http://i-proving.com/space/Jessamyn+Smith/blog/2008-06-16_1

http://i-proving.com/space/Jessamyn+Smith/blog/2008-06-16_1

To alter the unique settings on the repository in Artifactory - log in as an admin - and select edit on the relevant repo - screenshot here:

要在 Artifactory 中更改存储库上的唯一设置 - 以管理员身份登录 - 并选择相关存储库上的编辑 - 此处的屏幕截图:

http://wiki.jfrog.org/confluence/display/RTF/Understanding+Repositories

http://wiki.jfrog.org/confluence/display/RTF/Understanding+Repositories

回答by Brian Fox

Using non-unique snapshots is not a good way to go. Instead get a repository manager that can clean up snapshots and configure that to keep disk space down. Having the timestamped snapshots makes it much easier to track down issues since you can easily see which version actually is being used.

使用非唯一快照不是一个好方法。而是获得一个可以清理快照并配置它以减少磁盘空间的存储库管理器。拥有带时间戳的快照可以更轻松地跟踪问题,因为您可以轻松查看实际使用的是哪个版本。

回答by user188269

Artifactory can clean up old unique snapshots. However, we have found unique snapshots to be non-useful for the purpose of tracking down dependencies or rolling-back to a specific version. There are better alternatives for doing this, which are cleaner and more reliable. That is why Artifactory defaults to prefer non-unique snapshots, and this policy can be centrallycontrolled (which is unique to Artifactory). You can read more about this, as well as the auto-cleanup feature here.

Artifactory 可以清理旧的独特快照。但是,我们发现独特的快照对于跟踪依赖项或回滚到特定版本的目的是无用的。有更好的替代方法可以做到这一点,它们更干净、更可靠。这就是 Artifactory 默认优先选择非唯一快照的原因,并且该策略可以集中控制(这是 Artifactory 独有的)。您可以在此处阅读有关此内容以及自动清理功能的更多信息

回答by Cathy

<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>

回答by jprism

Will NOT work in Maven 3 as it was quoted by Apache below

不会在 Maven 3 中工作,因为它被下面的 Apache 引用

It's not recommended to use non-unique snapshots since they lead to non-reproducible builds. The main use case for these was to save disk space in the repository, but this is best handled by scheduling a periodic snapshot removal task to keep the number of versions down