我对Maven快照的含义有点困惑,为什么我们要构建一个?


当前回答

Maven版本可以包含一个字符串文字“SNAPSHOT”,以表示项目目前正在积极开发中。

例如,如果您的项目有一个“1.0-SNAPSHOT”版本,并且您将这个项目的工件部署到Maven存储库, 如果您愿意,Maven会将这个版本扩展到“1.0-20080207-230803-1” 在UTC 2008年2月7日11:08 PM部署一个版本。换句话说,当你 部署一个快照,您不是在发布一个软件组件;你是 在特定时间释放组件的快照。

因此,快照版本主要用于正在积极开发的项目。 如果您的项目依赖于正在积极开发的软件组件, 您可以依赖快照发布,Maven将定期尝试 运行构建时从存储库下载最新快照。类似地,如果 您的系统的下一个发行版将有一个“1.8”版本,您的项目也会如此 “1.8-SNAPSHOT”版本,直到正式发布。

例如,下面的依赖项总是会下载最新的1.8版本的spring开发JAR:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>1.8-SNAPSHOT”</version>
    </dependency>

Maven

maven发布过程的一个例子

其他回答

understanding the context of SDLC will help understand the difference between snapshot and the release. During the dev process developers all contribute their features to a baseline branch. At some point the lead thinks enough features have accumulated then he will cut a release branch from the baseline branch. Any builds prior to this time point are snapshots. Builds post to this point are releases. Be noted, release builds could change too before going to production if any defect spot during the release testing.

Maven中的快照版本是尚未发布的版本。

其思想是,在1.0发行版(或任何其他发行版)完成之前,存在1.0- snapshot。这个版本可能会变成1.0。它基本上是“正在开发的1.0版本”。这可能接近于真正的1.0发行版,或者相当远(例如,就在0.9发行版之后)。

“真实”版本和快照版本之间的区别是快照可能会得到更新。这意味着今天下载1.0-SNAPSHOT的文件可能与昨天或明天下载的文件不同。

通常,快照依赖关系应该只存在于开发过程中,没有发布版本(即没有非快照版本)应该依赖于快照版本。

“快照”术语意味着构建是给定时间内代码的快照。

这通常意味着这个版本仍在大量开发中。

当代码准备好并且是时候发布它时,您将希望更改POM中列出的版本。然后,您将使用“1.0”这样的标签,而不是使用“SNAPSHOT”。

有关版本控制的帮助,请查看语义版本控制规范。

通常在maven中,我们有两种类型的构建 1)建立快照 2)制定版本发布

快照构建:快照是特殊版本,它指示当前部署副本,不像常规版本,maven检查远程存储库中的每个构建的版本 因此快照构建只是开发构建。 发布版本:发布意味着在版本中删除快照,这些是常规的构建版本。

A Maven SNAPSHOT is an artifact created by a Maven build and pretends to help developers in the software development cycle. A SNAPSHOT is an artifact (or project build result ) that is not pretended to be used anywhere, it's only a temporarily .jar, ear, ... created to test the build process or to test new requirements that are not yet ready to go to a production environment. After you are happy with the SNAPSHOT artifact quality, you can create a RELEASE artifact that can be used by other projects or can be deployed itself.

在你的项目中,你可以使用Maven的pom.xml文件中的version元素定义一个SNAPSHOT:

<groupId>example.project.maven</groupId>
<artifactId>MavenEclipseExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Maven pom example</description>

如果你想更好地理解Maven,你也可以看看这些文章:

https://connected2know.com/programming/menu-maven-articles/