Maven:如何确保在时间戳记中使用带时间戳的快照版本? [英] Maven: How to ensure timestamped versions of snapshots are used in classpath?

查看:1080
本文介绍了Maven:如何确保在时间戳记中使用带时间戳的快照版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我们的功能测试可以在类路径中使用带时间戳的快照版本(例如api-0.5.0-20110706.191935-1.jar)从Maven运行.但是,虽然我可以看到在Artifactory存储库中有带有时间戳的版本,但Maven引用的是api-0.5.0-SNAPSHOT.jar并从本地存储库中对其进行解析.

I would like our functional tests to run from Maven using the timestamped version (e.g. api-0.5.0-20110706.191935-1.jar) of snapshots in the classpath. However, while I can see that we have timestamped versions sitting in our Artifactory repository Maven is referring to api-0.5.0-SNAPSHOT.jar and resolving it from the local repository.

背景 我们的持续集成(CI)服务器建立了两个相关的构建. Server构建运行mvn deploy,新快照将在正确构建的存储库中显示.

Background Our continuous integration (CI) server has two relevant builds set up. The Server build runs mvn deploy and the new snapshots turn up in the repository correctly built.

我们还有一个功能测试版本,该版本可以获取最新的正确版本,然后部署到开发服务器,然后开始针对该服务器运行测试.

We also have a functional test build which gets the latest correct build, deploys to a development server and then starts running tests against it.

似乎正在发生的功能测试构建依赖于API-0.5.0-SNAPSHOT.jar.当Server构建运行时,它将替换本地存储库中的快照,然后我们开始从功能测试构建中获取NoClassDeFond错误.

What appears to be happening is that the functional test build relies on API-0.5.0-SNAPSHOT.jar. When the Server build runs it replaces the snapshot in the local repository and we start getting NoClassDeFond errors from the functional test build.

因此,我希望功能测试版本使用带有时间戳的版本.

Hence, I want the functional test build to use the timestamped versions.

我目前知道的选项:

  1. 在POM中声明一个快照存储库,并确保uniqueVersion为true(我将很快尝试运行此版本).
  2. 使用version lock:snapshots目标将pom中的版本设置为带有时间戳的版本.
  3. 考虑一次从CI服务器调用来运行服务器构建和功能测试. (即删除服务器版本).
  1. Declare a snapshot repository in the POM and ensure uniqueVersion is true (I will shortly run a build trying this).
  2. Use the version lock:snapshots goal to set the versions in the pom to the timestamped version.
  3. Consider running the server build and functional tests in one invocation from the CI server. (i.e. removing the Server build).

推荐答案

以下是简短的答案:不要在CI构建中的项目之间使用SNAPSHOT依赖关系.它们在您的本地计算机上很好,但是CI环境往往无法正常运行**. SNAPSHOT的解决方法已发布,但情况一团糟.取而代之的是,只需使用常规依赖项,并在CI中有一个发布作业即可产生发布.

Here is the short answer: don't use SNAPSHOT dependencies between projects on your CI build. They are fine on your local machine, but CI environments tend to not work well**. There is a published algo for how SNAPSHOTs are resolved, but it's a mess. Instead, just use normal dependencies, and have a release job in your CI that produces releases.

换句话说,应该将SNAPSHOT视为本质上不确定的(至少从CI构建代理的角度来看).

Put another way, SNAPSHOTs should be considered essentially non-deterministic (at least from the point of view of a CI build agent).

版本插件可能有助于跟踪依赖关系.

The Versions plugin may be helpful for tracking dependencies.

**我看到它能够始终如一地工作的唯一方法是,如果您为每个构建代理设置了一个不同的存储库,然后在每次运行之间将其清除.剧烈,可怕,低效且不需要.

** The only way I've seen it work consistently is if you set up a different repository for each build agent, and then wipe it out between each run. Drastic, horrible, inefficient and unneeded.

这篇关于Maven:如何确保在时间戳记中使用带时间戳的快照版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆