Gitflow Workflow with Maven - when to build what?

核能气质少年 提交于 2020-05-16 02:05:40

问题


Gitflow introduces several branches like develop, release, hotfix, and also encourages feature branches.

In a Maven project, you usually build SNAPSHOT and release versions, and often number them with semantic, three-digit versions.

It would be sensible to automate the build process as much as possible, but the question is: When should we build a SNAPSHOT version, when should be build a release version, when should we build none of that at all?

I image the following could be sensible:

  • Whenever a feature branch is merged back into develop, a SNAPSHOT build is triggered and deployed to the Maven repository.
  • When a release branch is created, as release build is started.

But there are much more situations:

  • When I fix bugs on the release (or hotfix) branch, do I always want a new release build?
  • During developing a feature, should I build on the feature branch? If so, what should this version be called (1.2.3-FEATURE1-SNAPSHOT?)?

回答1:


Let's start with releases. Whether a version is going to be released or not is decided in the future when an already-built binary is deployed to TST envs and checked. When committing or building you can't predict whether the version will be a "release".

Once you abandon these ideas things will become much simpler. And since you can't use branch-based versions for releases, what's the point of making things different for feature branches? You might as well forget about mixing the concepts of branching and versioning together.

With Continuous Delivery (you can borrow its ideas even if you don't use it to the fullest) any build may potentially go to PRD, thus:

  1. Build a binary with any type of versioning that you like. With Maven the easiest is to stick with SNAPSHOT* and never use "release" ones. It's unique, it's standard, it has some advantages with Nexus (retention policies).
  2. When you're ready to go to PRD and the release version is chosen - tag it somehow. It can be a CI Job that keeps track of all PRD deployments; or you may have a page with all the release versions; or you may transfer the binary to another Maven repo (still can be a SNAPSHOT type). The latter is convenient if you go with retention policies for the snapshots.

Also we usually want to mention from which commit the binary was built. You can put this into the binary (some kind of version.properties) during the build time. You may even create an endpoint in your app that servers this version for convenience.

PS: if you simply want to follow GitFlow advice - there's an official page for the versioning. But you'll have all the problems (and more) that you already mentioned in the question.

* Maven automatically resolves SNAPSHOT versions into timestamp-ones. But you can't actually use this functionality because the timestamp is going to be different for different artifcacts during the build. If you want to keep version the same across all the binaries in the build you need to generate and assign a timestamp version manually using versions:set. It's not complicated, but is worth mentioning.



来源:https://stackoverflow.com/questions/60855587/gitflow-workflow-with-maven-when-to-build-what

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!