I am a bit confused about the meaning of a Maven Snapshot and why we build one?
我对Maven快照的含义以及为什么要构建它感到有点困惑。
7 个解决方案
#1
692
A snapshot version in Maven is one that has not been released.
Maven中的快照版本尚未发布。
The idea is that before a 1.0
release (or any other release) is done, there exists a 1.0-SNAPSHOT
. That version is what might become 1.0
. It's basically "1.0
under development". This might be close to a real 1.0
release, or pretty far (right after the 0.9
release, for example).
这个想法是在1.0版(或其他版本)发布之前,存在一个1.0快照。这个版本可能会变成1.0。它基本上是“正在开发中的1.0”。这可能接近于真正的1.0版本,或者相当远(例如,在0.9版本之后)。
The difference between a "real" version and a snapshot version is that snapshots might get updates. That means that downloading 1.0-SNAPSHOT
today might give a different file than downloading it yesterday or tomorrow.
“真实”版本和快照版本之间的区别在于快照可能获得更新。这意味着今天下载1.0快照可能会提供不同于昨天或明天下载的文件。
Usually, snapshot dependencies should only exist during development and no released version (i.e. no non-snapshot) should have a dependency on a snapshot version.
通常,快照依赖关系应该只在开发期间存在,而没有发布的版本(也就是说没有非快照)应该依赖于快照版本。
#2
645
The three others answers provide you a good vision of what a -SNAPSHOT
version is. I just wanted to add some information regarding the behavior of Maven when it finds a SNAPSHOT
dependency.
其他三个答案为您提供了一个关于快照版本的良好远景。我只是想在Maven找到快照依赖性时添加一些关于Maven行为的信息。
When you build an application, Maven will search for dependencies in the local repository. If a stable version is not found there, it will search the remote repositories (defined in settings.xml
or pom.xml
) to retrieve this dependency. Then, it will copy it into the local repository, to make it available for the next builds.
在构建应用程序时,Maven将在本地存储库中搜索依赖项。如果没有找到稳定的版本,它将搜索远程存储库(在设置中定义)。检索此依赖项。然后,它会将其复制到本地存储库中,以使其可用于下一个构建版本。
For example, a foo-1.0.jar
library is considered as a stable version, and if Maven finds it in the local repository, it will use this one for the current build.
例如,foo - 1.0。jar库被认为是一个稳定的版本,如果Maven在本地存储库中找到它,它将使用这个库来进行当前的构建。
Now, if you need a foo-1.0-SNAPSHOT.jar
library, Maven will know that this version is not stable and is subject to changes. That's why Maven will try to find a newer version in the remote repositories, even if a version of this library is found on the local repository. However, this check is made only once per day. That means that if you have a foo-1.0-20110506.110000-1.jar
(i.e. this library has been generated on 2011/05/06 at 11:00:00) in your local repository, and if you run the Maven build again the same day, Maven will not check the repositories for a newer version.
现在,如果您需要一个foo-1.0-SNAPSHOT。jar库,Maven会知道这个版本不稳定,并且会发生变化。这就是为什么Maven会尝试在远程存储库中找到一个较新的版本,即使这个库的版本在本地存储库中找到。然而,这张支票每天只做一次。这意味着如果你有一个foo-1.0-20110506.110000-1。jar(也就是说,这个库是在2011/05/06在您的本地存储库中生成的),如果您在同一天运行Maven构建,Maven将不会检查存储库的更新版本。
Maven provides you a way to can change this update policy in your repository definition:
Maven为您提供了一种方法,可以在您的存储库定义中更改此更新策略:
<repository>
<id>foo-repository</id>
<url>...</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>XXX</updatePolicy>
</snapshots>
</repository>
where XXX
can be:
XXX可以是:
- always: Maven will check for a newer version on every build;
- 总是:Maven将在每个构建上检查更新的版本;
- daily, the default value;
- 每天,默认值;
- interval:XXX: an interval in minutes (XXX)
- 间隔:XXX:分分钟(XXX)
-
never: Maven will never try to retrieve another version. It will do that only if it doesn't exist locally. With the configuration,
SNAPSHOT
version will be handled as the stable libraries. - 永远不会:Maven不会尝试检索另一个版本。只有在本地不存在时,它才会这样做。通过配置,快照版本将被处理为稳定的库。
(model of the settings.xml can be found here)
(模型的设置。xml可以在这里找到)
#3
50
The "SNAPSHOT" term means that the build is a snapshot of your code at a given time.
“快照”术语意味着在给定的时间内构建是您的代码的快照。
It usually means that the version is a version still under heavy development.
这通常意味着该版本仍然处于严重的开发阶段。
When it comes time to release your code, you will want to change the version listed in the pom. So instead of having a "SNAPSHOT" you would have something like "1.0".
在发布代码的时候,您需要更改pom中列出的版本。因此,与其有一个“快照”,你会有类似“1.0”的东西。
For some help with versioning, check out the Semantic Versioning specification.
对于版本控制的一些帮助,请查看语义版本控制规范。
#4
19
A "release" is the final build for a version which does not change.
“release”是一个版本的最终版本,它不会改变。
A "snapshot" is a build which can be replaced by another build which has the same name. It is implies the build could change at any time and is still under active development.
“快照”是一个可以被另一个具有相同名称的构建所替代的构建。这意味着构建可以在任何时候发生变化,并且仍在积极的开发中。
You have different artifacts for different builds based on the same code. E.g. you might have one with debugging and one without. One for Java 5.0 and one for Java 6. Generally its simpler to have one build which does everything you need. ;)
基于相同的代码,您可以对不同的构建有不同的工件。例如,您可能有一个调试器,一个没有。一个用于Java 5.0,一个用于Java 6。一般来说,拥有一个可以满足您所有需求的构建更简单。,)
#5
4
Maven versions can contain a string literal "SNAPSHOT" to signify that a project is currently under active development.
Maven版本可以包含字符串字面量“快照”,以表示项目目前正在积极开发中。
For example, if your project has a version of “1.0-SNAPSHOT” and you deploy this project’s artifacts to a Maven repository, Maven would expand this version to “1.0-20080207-230803-1” if you were to deploy a release at 11:08 PM on February 7th, 2008 UTC. In other words, when you deploy a snapshot, you are not making a release of a software component; you are releasing a snapshot of a component at a specific time.
例如,如果您的项目有一个版本的“1.0-SNAPSHOT”,并且您将该项目的工件部署到Maven存储库,那么Maven将把这个版本扩展到“1.0-20080207-230803-1”,如果您要在2008年2月7日晚上11点08分部署一个发布版本的话。换句话说,当您部署一个快照时,您不会发布一个软件组件;您将在特定的时间发布组件的快照。
So mainly snapshot versions are used for projects under active development. If your project depends on a software component that is under active development, you can depend on a snapshot release, and Maven will periodically attempt to download the latest snapshot from a repository when you run a build. Similarly, if the next release of your system is going to have a version “1.8,” your project would have a “1.8-SNAPSHOT” version until it was formally released.
因此,主要的快照版本用于正在开发的项目。如果您的项目依赖于正在开发的软件组件,您可以依赖于快照发布,而Maven将在运行构建时定期尝试从存储库下载最新的快照。类似地,如果您的系统的下一个版本将有一个版本“1.8”,那么您的项目将有一个“1.8快照”版本,直到它正式发布。
For example , the following dependency would always download the latest 1.8 development JAR of spring:
例如,下面的依赖项总是下载最新的1.8开发JAR:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>1.8-SNAPSHOT”</version>
</dependency>
Maven
An example of maven release process
一个maven发布过程的示例。
#6
3
This is how a snapshot looks like for a repository and in this case is not enabled, which means that the repository referred in here is stable and there's no need for updates.
这是存储库的快照,在此情况下是不启用的,这意味着这里所引用的存储库是稳定的,不需要更新。
<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>
Another case would be for:
另一个例子是:
<snapshots>
<enabled>true</enabled>
</snapshots>
which means that Maven will look for updates for this repository. You can also specify an interval for the updates with tag.
这意味着Maven将查找该存储库的更新。您还可以为更新的标签指定一个间隔。
#7
1
usually in maven we have two types of builds 1)Snapshot builds 2)Release builds
通常在maven中,我们有两种构建快照构建版本。
1)snapshot builds:SNAPSHOT is the special version that indicate current deployment copy not like a regular version, maven checks the version for every build in the remote repository so the snapshot builds are nothing but maintainance builds.
1)快照构建:快照是表示当前部署副本不像常规版本的特殊版本,maven检查远程存储库中的每个构建版本,因此快照构建只是维护构建。
2)Release builds:Release means removing the SNAPSHOT at the version for the build, these are the regular build versions.
2)发布版本:发布意味着在构建版本中删除快照,这些是常规构建版本。
#1
692
A snapshot version in Maven is one that has not been released.
Maven中的快照版本尚未发布。
The idea is that before a 1.0
release (or any other release) is done, there exists a 1.0-SNAPSHOT
. That version is what might become 1.0
. It's basically "1.0
under development". This might be close to a real 1.0
release, or pretty far (right after the 0.9
release, for example).
这个想法是在1.0版(或其他版本)发布之前,存在一个1.0快照。这个版本可能会变成1.0。它基本上是“正在开发中的1.0”。这可能接近于真正的1.0版本,或者相当远(例如,在0.9版本之后)。
The difference between a "real" version and a snapshot version is that snapshots might get updates. That means that downloading 1.0-SNAPSHOT
today might give a different file than downloading it yesterday or tomorrow.
“真实”版本和快照版本之间的区别在于快照可能获得更新。这意味着今天下载1.0快照可能会提供不同于昨天或明天下载的文件。
Usually, snapshot dependencies should only exist during development and no released version (i.e. no non-snapshot) should have a dependency on a snapshot version.
通常,快照依赖关系应该只在开发期间存在,而没有发布的版本(也就是说没有非快照)应该依赖于快照版本。
#2
645
The three others answers provide you a good vision of what a -SNAPSHOT
version is. I just wanted to add some information regarding the behavior of Maven when it finds a SNAPSHOT
dependency.
其他三个答案为您提供了一个关于快照版本的良好远景。我只是想在Maven找到快照依赖性时添加一些关于Maven行为的信息。
When you build an application, Maven will search for dependencies in the local repository. If a stable version is not found there, it will search the remote repositories (defined in settings.xml
or pom.xml
) to retrieve this dependency. Then, it will copy it into the local repository, to make it available for the next builds.
在构建应用程序时,Maven将在本地存储库中搜索依赖项。如果没有找到稳定的版本,它将搜索远程存储库(在设置中定义)。检索此依赖项。然后,它会将其复制到本地存储库中,以使其可用于下一个构建版本。
For example, a foo-1.0.jar
library is considered as a stable version, and if Maven finds it in the local repository, it will use this one for the current build.
例如,foo - 1.0。jar库被认为是一个稳定的版本,如果Maven在本地存储库中找到它,它将使用这个库来进行当前的构建。
Now, if you need a foo-1.0-SNAPSHOT.jar
library, Maven will know that this version is not stable and is subject to changes. That's why Maven will try to find a newer version in the remote repositories, even if a version of this library is found on the local repository. However, this check is made only once per day. That means that if you have a foo-1.0-20110506.110000-1.jar
(i.e. this library has been generated on 2011/05/06 at 11:00:00) in your local repository, and if you run the Maven build again the same day, Maven will not check the repositories for a newer version.
现在,如果您需要一个foo-1.0-SNAPSHOT。jar库,Maven会知道这个版本不稳定,并且会发生变化。这就是为什么Maven会尝试在远程存储库中找到一个较新的版本,即使这个库的版本在本地存储库中找到。然而,这张支票每天只做一次。这意味着如果你有一个foo-1.0-20110506.110000-1。jar(也就是说,这个库是在2011/05/06在您的本地存储库中生成的),如果您在同一天运行Maven构建,Maven将不会检查存储库的更新版本。
Maven provides you a way to can change this update policy in your repository definition:
Maven为您提供了一种方法,可以在您的存储库定义中更改此更新策略:
<repository>
<id>foo-repository</id>
<url>...</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>XXX</updatePolicy>
</snapshots>
</repository>
where XXX
can be:
XXX可以是:
- always: Maven will check for a newer version on every build;
- 总是:Maven将在每个构建上检查更新的版本;
- daily, the default value;
- 每天,默认值;
- interval:XXX: an interval in minutes (XXX)
- 间隔:XXX:分分钟(XXX)
-
never: Maven will never try to retrieve another version. It will do that only if it doesn't exist locally. With the configuration,
SNAPSHOT
version will be handled as the stable libraries. - 永远不会:Maven不会尝试检索另一个版本。只有在本地不存在时,它才会这样做。通过配置,快照版本将被处理为稳定的库。
(model of the settings.xml can be found here)
(模型的设置。xml可以在这里找到)
#3
50
The "SNAPSHOT" term means that the build is a snapshot of your code at a given time.
“快照”术语意味着在给定的时间内构建是您的代码的快照。
It usually means that the version is a version still under heavy development.
这通常意味着该版本仍然处于严重的开发阶段。
When it comes time to release your code, you will want to change the version listed in the pom. So instead of having a "SNAPSHOT" you would have something like "1.0".
在发布代码的时候,您需要更改pom中列出的版本。因此,与其有一个“快照”,你会有类似“1.0”的东西。
For some help with versioning, check out the Semantic Versioning specification.
对于版本控制的一些帮助,请查看语义版本控制规范。
#4
19
A "release" is the final build for a version which does not change.
“release”是一个版本的最终版本,它不会改变。
A "snapshot" is a build which can be replaced by another build which has the same name. It is implies the build could change at any time and is still under active development.
“快照”是一个可以被另一个具有相同名称的构建所替代的构建。这意味着构建可以在任何时候发生变化,并且仍在积极的开发中。
You have different artifacts for different builds based on the same code. E.g. you might have one with debugging and one without. One for Java 5.0 and one for Java 6. Generally its simpler to have one build which does everything you need. ;)
基于相同的代码,您可以对不同的构建有不同的工件。例如,您可能有一个调试器,一个没有。一个用于Java 5.0,一个用于Java 6。一般来说,拥有一个可以满足您所有需求的构建更简单。,)
#5
4
Maven versions can contain a string literal "SNAPSHOT" to signify that a project is currently under active development.
Maven版本可以包含字符串字面量“快照”,以表示项目目前正在积极开发中。
For example, if your project has a version of “1.0-SNAPSHOT” and you deploy this project’s artifacts to a Maven repository, Maven would expand this version to “1.0-20080207-230803-1” if you were to deploy a release at 11:08 PM on February 7th, 2008 UTC. In other words, when you deploy a snapshot, you are not making a release of a software component; you are releasing a snapshot of a component at a specific time.
例如,如果您的项目有一个版本的“1.0-SNAPSHOT”,并且您将该项目的工件部署到Maven存储库,那么Maven将把这个版本扩展到“1.0-20080207-230803-1”,如果您要在2008年2月7日晚上11点08分部署一个发布版本的话。换句话说,当您部署一个快照时,您不会发布一个软件组件;您将在特定的时间发布组件的快照。
So mainly snapshot versions are used for projects under active development. If your project depends on a software component that is under active development, you can depend on a snapshot release, and Maven will periodically attempt to download the latest snapshot from a repository when you run a build. Similarly, if the next release of your system is going to have a version “1.8,” your project would have a “1.8-SNAPSHOT” version until it was formally released.
因此,主要的快照版本用于正在开发的项目。如果您的项目依赖于正在开发的软件组件,您可以依赖于快照发布,而Maven将在运行构建时定期尝试从存储库下载最新的快照。类似地,如果您的系统的下一个版本将有一个版本“1.8”,那么您的项目将有一个“1.8快照”版本,直到它正式发布。
For example , the following dependency would always download the latest 1.8 development JAR of spring:
例如,下面的依赖项总是下载最新的1.8开发JAR:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>1.8-SNAPSHOT”</version>
</dependency>
Maven
An example of maven release process
一个maven发布过程的示例。
#6
3
This is how a snapshot looks like for a repository and in this case is not enabled, which means that the repository referred in here is stable and there's no need for updates.
这是存储库的快照,在此情况下是不启用的,这意味着这里所引用的存储库是稳定的,不需要更新。
<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>
Another case would be for:
另一个例子是:
<snapshots>
<enabled>true</enabled>
</snapshots>
which means that Maven will look for updates for this repository. You can also specify an interval for the updates with tag.
这意味着Maven将查找该存储库的更新。您还可以为更新的标签指定一个间隔。
#7
1
usually in maven we have two types of builds 1)Snapshot builds 2)Release builds
通常在maven中,我们有两种构建快照构建版本。
1)snapshot builds:SNAPSHOT is the special version that indicate current deployment copy not like a regular version, maven checks the version for every build in the remote repository so the snapshot builds are nothing but maintainance builds.
1)快照构建:快照是表示当前部署副本不像常规版本的特殊版本,maven检查远程存储库中的每个构建版本,因此快照构建只是维护构建。
2)Release builds:Release means removing the SNAPSHOT at the version for the build, these are the regular build versions.
2)发布版本:发布意味着在构建版本中删除快照,这些是常规构建版本。