Handling Maven "settings.xml" for local dev and CI builds


I’m trying to automate a few common steps for a small team of Java devs, but I’m not a Java guy myself and they’re more accustomed to Ant than Maven… I’ve done a great deal of research and testing over the past few months, but there are a few points here that I’m not quite sure about.

So far, the steps in this awesomely helpful post have been most predictable way I’ve found to configure a project to deploy to my custom Artifactory instance from GitLab CI, the majority of my searching for info on achieving this has looped back to this specific post in some way. The only part about it that concerns me is needing to have a .m2/settings.xml file inside every project.

Since it’s a small team that works from one central location (sometimes off-site with laptops, but not often), I’m looking at the following overall structure:

  • Artifactory instance on a private hosted server - used to collect and serve only release level artifacts from our own projects. I don’t even want to use this to cache other remote repositories.
  • Artifactory instance on a LAN server - used to collect and serve development snapshots, as well as cache release artifacts on demand from the remote server and third-party remote repositories.

This idea is my attempt at making the following possible:

  • New releases will only come from a GitLab CI build, so only that “user” will have the ability to publish to the remote server.
  • WIP snapshot builds will only come from and be used by developers, so they will need the ability to publish them to the local server. Obviously, they must still be able to fetch release repositories, hence the local cached copy of the remote.
  • Collecting release artifacts to prepare a new product release (comprised of multiple project release artifacts) should be done from the release repositories only, whether this comes from the local or the remote server probably doesn’t make much difference (other than download times).

What I’m battling the most to understand here is the project POM’s distributionManagement section and as a by product, the associated server definitions in the settings.xml file.

Would I be able to simply extend the GitLab example’s distributionManagement section with repository and snapshotRepository rules, where releases go to outtheresomewhere.com/artifactory and snapshots go to localserver.net/artifactory?

Should I perhaps keep things even simpler and just use a single Artifactory instance instead?

Would it be worth looking at scripting the creation of the .m2/repository/ folder and .m2/settings.xml files for CI builds, in order to avoid needing them to exist inside the project source code repository?

Really hoping some of you good people can help clarify these points for me, this is a very exciting project for me, just feeling a tad overwhelmed by all the nitty-gritty details of strange build systems.