Proper maven projects versioning strategy

344 Views Asked by At

I have a development in course, based on many projects (each of which represents a microservice). All of them are using the Spring Boot Framework and must be compiled in Azure Devops in order to generate the final docker image that must be archived into Azure Artifacts.

  • Ideally, the project version should not be entered manually into the pom.xml file. That would make version changing tedious. Instead, gitversion is being used (GitVersion.yml file used to determine the version according to some rules (not the scope of this question))
$ gitversion | jq .SemVer     
"1.0.10"
  • Since Maven version 3.5 placeholders are allowed in version property and so, are being used:
    ...
    <artifactId>service1</artifactId>
    <version>${revision}${changelist}</version>
    ...

Locally this can be compiled with a mvn command like this one:

$ mvn clean package -Drevision=$(gitversion | jq .SemVer | sed 's/^"\|"$//g') -Dchangelist="-SNAPSHOT" -DskipTests=true

And in Azure, everything also works as expected thanks to this pipelines that makes usage of GitTools extension:

# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- checkout: self
  displayName: Git Checkout
  persistCredentials: true

- script: git fetch --unshallow
  displayName: Git Fetch

- task: gitversion/setup@0
  displayName: GitVersion Setup
  inputs:
    versionSpec: '5.x'

- task: gitversion/execute@0
  displayName: GitVersion Execute
  inputs:
    useConfigFile: true
    configFilePath: 'GitVersion.yml'

- task: Bash@3
  displayName: Display Semantic Version
  inputs:
    targetType: 'inline'
    script: |
      echo "Semantic Version equal to '$(GitVersion.SemVer)'"
      echo "Changelist equal to '$(changelist)'"

- task: Maven@3
  displayName: Maven Compilation
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.17'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    codeCoverageToolOption: 'JaCoCo'
    goals: 'package deploy -Drevision=$(GitVersion.SemVer) -Dchangelist=$(changelist)'
    options: '-DskipTests=true'
    mavenAuthenticateFeed: true
    effectivePomSkip: true

- task: Docker@2
  displayName: Build and Push Docker image
  inputs:
    containerRegistry: 'mycontainerregistry'
    repository: 'service1'
    dockerfile: 'Dockerfile'
    command: 'buildAndPush'
    tags: |
      $(GitVersion.SemVer)$(changelist)
      latest

So basically all requirements are satisfied except for the following issue:

I have intentionally forgotten one important thing, some projects are treated as libraries, and so, are being used/imported by the other projects. Here is where versioning gains importance.

  1. IDE (STS (eclipse fork)) is not capable (or at least i have no idea of setting it up properly) of resolving those version placeholders. This is uncomfortable to navigate through source code (see attached image) but mainly, it is very annoying because it affects the development flow:

Source not found

make changes in library requires...

  1. git commit
  2. azure compilation
  3. jar download from artifacts

...in order to apply those changes in project that makes usage of it. Of course I would like that flow to be completely transparent.

0

There are 0 best solutions below