简体   繁体   English

Jenkins Maven发布:替换快照依赖项

[英]Jenkins Maven Release: Replace Snapshot Dependencies

In one of our maven projects, we have a dependency to a Commons-POM, which is also used by other projects and therefore not part of the Parent-POM . 在我们的一个maven项目中,我们依赖于Commons-POM,它也被其他项目使用,因此不属于Parent-POM Since it is also under development we refer to the SNAPSHOT version. 由于它也在开发中,我们参考SNAPSHOT版本。

When creating a release with Jenkins, it will use the snapshot dependency. 使用Jenkins创建发行版时,它将使用快照依赖项。 But what we want is to use the latest release or simply replace the snapshot with the release version. 但我们想要的是使用最新版本或只是用发布版本替换快照。

So is it possible in Jenkins to replace the snapshot versions? 那么Jenkins可以替换快照版本吗? Maybe the same way, Maven Release plugin does it when performing manually (it prompts for resolving the dependencies)? 也许以同样的方式,Maven Release插件在手动执行时会执行此操作(它会提示解析依赖项)?

The Versions Maven Plugin offers the goal versions:use-latest-releases . 版本Maven插件提供了目标版本:use-latest-releases You can use this goal in a pre-step maven call prior to your your regular build like this: 您可以在常规构建之前的预执行maven调用中使用此目标,如下所示:

versions:use-latest-releases -Dincludes=com.yourcompany.yourgroupid:yourartifactid versions:commit scm:checkin

That way, you can keep the SNAPSHOT dependency until the artifact is actually released. 这样,您可以保持SNAPSHOT依赖性,直到实际释放工件。

Maybe it's possible with not hardcoding the version but having a parameter ( <version>${dependency.version}</version> ) and then starting the build with mvn clean install -Ddependecy.version=VERSION (in Jenkins you can parametrize builds). 也许没有硬编码版本但有一个参数( <version> $ {dependency.version} </ version> )然后用mvn clean install启动构建-Ddependecy.version = VERSION (在Jenkins中你可以参数化构建) 。 But this is nothing more than a hack! 但这只不过是一个黑客!

Having SNAPSHOT dependencies during development is ok (and sometimes a pain ;-) but before releasing your project you should release the dependency. 在开发过程中有SNAPSHOT依赖项是可以的(有时很痛苦;-)但是在发布项目之前你应该释放依赖项。

If the development of the commons project is (currently) tightly coupled to your project you could consider having the commons project in the same release cycle like your project for the time being. 如果公共项目的开发(当前)与您的项目紧密耦合,您可以考虑让公共项目在与项目暂时相同的发布周期中进行。

M2 Release插件是围绕标准Maven发布插件的Jenkins包装器。

I have the same issue and got some mileage out of the following solution. 我有同样的问题,并从以下解决方案中获得了一些好处。 In Maven Non-Interactive releases , at the bottom of the page it describes using a releases.properties file to define the versions. Maven非交互式版本中 ,它在页面底部描述了使用releases.properties文件来定义版本。

Rather than hand cranking this file, I first ran maven locally using: 我没有手动启动这个文件,而是首先使用以下方式在本地运行maven:

mvn -U release:prepare -DdryRun=true -Dresume=false

After answering all the questions, it creates the releases.properties file you would like to use. 在回答完所有问题后,它会创建您要使用的releases.properties文件。 The only thing that needs to be done is to edit the release.properties file. 唯一需要做的就是编辑release.properties文件。

At the end of the file is: 在文件的末尾是:

completedPhase=end-release

change this to: 将此更改为:

completedPhase=check-dependency-snapshots

see: Maven Release Plugin phases This will have the effect of short circuiting the scm-check-modifications but you are on a build server, so there should be no local modifications. 请参阅: Maven Release Plugin阶段这将产生短路scm-check-modification的效果,但您在构建服务器上,因此不应进行本地修改。

I checked this file in to our scm at the root of the project (same level as the pom) 我在项目的根目录中检查了这个文件到我们的scm(与pom相同的级别)

On jenkins, I then have these settings for release: 在詹金斯,然后我有这些设置发布:

--batch-mode release:prepare release:perform

It seems a bit messy to me. 这对我来说似乎有些混乱。 I am hopeful there is a cleaner way. 我希望有一种更清洁的方式。 [Running: Jenkins 1.533, Jenkins Maven Release Plug-in Plug-in 0.12.0, Maven Integration plugin 1.533] [运行:Jenkins 1.533,Jenkins Maven发布插件插件0.12.0,Maven集成插件1.533]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM