我对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/
其他回答
快照仅仅意味着Maven将根据您的配置检查特定依赖项的最新更改。快照是不稳定的,因为它是在开发中,但如果在一个特殊的项目需要有最新的变化,你必须配置你的依赖版本为快照版本。这种情况发生在拥有多个产品的大型组织中,这些产品彼此密切相关。
“快照”术语意味着构建是给定时间内代码的快照。
这通常意味着这个版本仍在大量开发中。
当代码准备好并且是时候发布它时,您将希望更改POM中列出的版本。然后,您将使用“1.0”这样的标签,而不是使用“SNAPSHOT”。
有关版本控制的帮助,请查看语义版本控制规范。
“发行版”是一个没有更改的版本的最终版本。
“快照”是一个可以被具有相同名称的另一个构建所替换的构建。这意味着构建可以在任何时候更改,并且仍然处于积极的开发中。
对于基于相同代码的不同构建,您有不同的工件。例如,你可能有一个调试和一个没有。一个用于Java 5.0,一个用于Java 6。一般来说,一个版本能满足你所有的需求会更简单。;)
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/
其他三个答案让您对-SNAPSHOT版本有了一个很好的了解。我只是想添加一些关于Maven在发现SNAPSHOT依赖项时的行为的信息。
在构建应用程序时,Maven将在本地存储库中搜索依赖项。如果在那里没有找到稳定版本,它将搜索远程存储库(在settings.xml或pom.xml中定义)以检索此依赖项。然后,它将把它复制到本地存储库中,使其可用于下一个构建。
例如,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.
Maven为您提供了一种在存储库定义中更改此更新策略的方法:
<repository>
<id>foo-repository</id>
<url>...</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>XXX</updatePolicy>
</snapshots>
</repository>
其中XXX可以是:
always: Maven将在每次构建时检查更新的版本; 每日,默认值; interval:XXX:单位为分钟的间隔(XXX)。 never: Maven永远不会尝试检索其他版本。它只在本地不存在时才会这样做。通过配置,SNAPSHOT版本将作为稳定库处理。
(settings.xml的模型可以在这里找到)
推荐文章
- Eclipse调试器总是阻塞在ThreadPoolExecutor上,没有任何明显的异常,为什么?
- Java生成两个给定值之间的随机数
- 如何有效地从数组列表或字符串数组中删除所有空元素?
- 比较JUnit断言中的数组,简洁的内置方式?
- codestyle;把javadoc放在注释之前还是之后?
- 如何在Spring中定义List bean ?
- 将Set<T>转换为List<T>的最简洁的方法
- 在JavaScript中,什么相当于Java的Thread.sleep() ?
- 使用Java重命名文件
- URL从Java中的类路径加载资源
- .toArray(new MyClass[0]) or .toArray(new MyClass[myList.size()])?
- Hibernate中不同的保存方法之间有什么区别?
- Java 8流和数组操作
- Java Regex捕获组
- Openssl不被视为内部或外部命令