3

I would like to have an external file, containing a single value - a version, such as 1.0 Then, I would like to reference this in my pom.xml, such that the version property will be set during build by the value I give to it This way I can have proper versioning on my jar without commiting changes using mvn to the entire reactor every time For example, something like:

<version>./version.txt</version>

And if the content of version.txt is 1.0, when I compile my code to a jar, mvn will evaluate the content of my file and set the jar version to 1.0

It slightly differs from properties file since my external file is not a key=value formatted file, its merely a value which I want to read in full and have it represent the value of a key in my pom.xml

buddy123
  • 5,679
  • 10
  • 47
  • 73
  • Possible duplicate of [How to read an external properties file in Maven](https://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file-in-maven) – OldProgrammer Feb 19 '19 at 14:39
  • Ill check. I didnt realize properties refer to anything, I thought its something specific – buddy123 Feb 19 '19 at 14:39
  • 1
    Personally, I would not recommend this. This would mean that if you forgot to update that file after making a release, you 're in for a surprise afterwards. – Stultuske Feb 19 '19 at 14:46
  • I agree in general @Stultuske but its a current flow I need to adapt myself into. And this file is a central location that specifies the version for the release of the entire software suite, so its actually fine (for this particular case, anyway) – buddy123 Feb 19 '19 at 15:29
  • 1
    I recommend to read this: https://maven.apache.org/maven-ci-friendly.html – khmarbaise Feb 19 '19 at 16:03

1 Answers1

1

You can achieve this by running the maven versions plugin before running your build

Your build script could loook something like this:

mvn -B -DnewVersion=$(cat ./version.txt) -DgenerateBackupPoms=false versions:set
mvn -B clean install
McGin
  • 1,361
  • 2
  • 13
  • 31