0

We are using a Maven for a while in our project and want to automate the release process little bit. we came up with the following idea so that the version will be maintained by developers or in SCM instead of in DevOps tool like jenkins/bamboo.

Anyone following below process instead of setting the interpolation value in arguments as "mvn install -Dapp.version=1.0.0-SNAPSHOPT"

The process we like to follow is to supply the Maven project version through an external property file.

let's assume the following partial POM.xml excerpt as example.

<project>
    <groupId>com.home.diary</groupId>
    <artifactId>journal</artifactId>
    <version>${app.version}</version>
    <packaging>war</packaging>
</project>

let's assume i have an version.properties file in my SCM with following content

app.version=2.0.0-RELEASE

while running the mvn goal

mvn install

i want the artifact generated as

journal-2.0.0-RELEASE

I tried using plugin properties-maven-plugin from org.codehaus.mojo as discussed here How to read an external properties file in Maven but it's not working.

Anyone did this? could you please share your implementation/ideas?

Dhana
  • 813
  • 1
  • 8
  • 19
  • Does this answer your question? [How to read an external properties file in Maven](https://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file-in-maven) – user1717259 Nov 08 '19 at 15:44
  • properties-maven-plugin is not applying the value to interpolation variable for `` tag and `` tag – Dhana Nov 08 '19 at 16:07

1 Answers1

1

This is not possible.

First of all: Why not just manage the version in the <version> tag itself? It is the easiest thing and fulfils your requirement (the developer manages the version in the SCM).

If you don't want this, you need to supply the version either in the POM itself or through the command line. Reading external properties with something like the properties maven plugin will always happen too late, i.e. after the version tag is already read.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Thanks for your reply. The reason for not using the in pom.xml is we have multiple dependent project and modules and all should follow same version. so we don't want to change the value of tag for all the dependent projects for everytime we release or commit. if it's maintained in one external file and it can be interpolated into all the pom.xml . maintaining version would be easy. – Dhana Nov 08 '19 at 16:17
  • If you want to always build the same set of projects with the same version, I would create a multi-module project in Maven. – J Fabian Meier Nov 08 '19 at 16:18
  • We have multi-module project with packaging as POM. the above is only example not the actual project. – Dhana Nov 08 '19 at 16:21
  • 1
    But inside a multi-module project, you don't have the version problem, because everything is always build with the same version. – J Fabian Meier Nov 08 '19 at 16:57