我对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发布过程的一个例子

其他回答

在开发阶段,Maven快照每天都会寻找更新的更高版本(如果在nexus存储库中可用),然后在本地下载它以备下一次构建。

您可以在存储库定义中设置四个选项

总是这样, 每日(默认), 间隔, 永远,

注意:在产品版本中,我们不应该依赖于快照版本。

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.

“发行版”是一个没有更改的版本的最终版本。

“快照”是一个可以被具有相同名称的另一个构建所替换的构建。这意味着构建可以在任何时候更改,并且仍然处于积极的开发中。

对于基于相同代码的不同构建,您有不同的工件。例如,你可能有一个调试和一个没有。一个用于Java 5.0,一个用于Java 6。一般来说,一个版本能满足你所有的需求会更简单。;)

这就是存储库的快照的样子,在本例中没有启用快照,这意味着这里引用的存储库是稳定的,不需要更新。

<project>
    ...
    <repositories>
        <repository>
            <id>lds-main</id>
            <name>LDS Main Repo</name>
            <url>http://code.lds.org/nexus/content/groups/main-repo</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

另一种情况是:

<snapshots>
        <enabled>true</enabled>
</snapshots>

这意味着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/