2

Our product is made up of different modules inside the same Git repository. Lets say we have "core" which has a maven dependency onto "api".

Now, when we are working on a specific feature/bugfix branch, we are running builds from it, so that testing can work with it.

All artifacts from all branches, end up in the same Maven repository, with the same version and classifiers. The modules do not get built together. So "api" may be built in the morning, and "core" in the afternoon.

The problem we have is that at the moment, if there has been builds in between, "core" may be getting the "api" snapshot build from another branch.

I imagine this is a common problem on teams working with a similar setup as us.

I am tempted to say, that the way to deal with this problem is to make the Maven coordinate between branches unique, either with a special classifier, or with a special suffix in the version directly.

Which approach should I follow?

lqbweb
  • 1,684
  • 3
  • 19
  • 33

2 Answers2

4

If you really want to build from different feature branches, put additional terms into the version number like 1.2.3-feature1-SNAPSHOT. This shows that you really build a different version of the same artifact, which also makes sure that you never add two "same" artifacts as dependencies in the same project.

See also

https://stackoverflow.com/a/48784315/927493

Maven best practices for versioning different branches [development, qa / pre-release]

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
1

In my experience, this normally isn't a problem because projects normally don't put builds from feature branches in the shared Maven repo.

Your build server should certainly be used to rebuild whenever a long-lived branch is updated (and the update to that branch should be consistent). It sounds like you're using gitflow; in that case you'd do a production build every time master is updated and a dev build every time develop is updated. Your master builds will have release version numbers, and your develop builds will have snapshot version numbers.

What use does it serve to have builds from the feature branches in the shared repository? For that matter, what use does it serve to have the build server involved in feature branches at all? Your developers can build and deploy locally to test feature branches (including updating their local maven repo if necessary), and as soon as they try to push a merge to develop that will trigger a CI build and catch anything they missed, right?

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52