0

I am working with maven projects . I want to read my version number from a property file and access this version variable into my pom.xml instead of updating each time in the 17.3-SNAPSHOT in the pom.xml . So when i want to update my version in a particular development sprint,the change should have only in the version number property in the property file and will be able to build jar file with the updated version . So I want to create a version config variable in an external property file (example : /main/resources/version_config.properties) and access this in pom.xml for the build process .

<dependency>
<group Id>x.x.x</group Id>
<artifact Id>maven-model</artifact Id>
<version>2.0</version>
</dependency>

instead of using the above version value(2.0) between version tag , i want to get this value from a property file names xxx.properties (property like , version.config.value=2.0) I tried the above solutions .Can any one help on on this ?

user3518223
  • 155
  • 1
  • 5
  • 13
  • What is the advantage of having an external file which contains the versions of dependencies which should be handled by using a dependencyManagement block in an appropriate parent pom...? – khmarbaise Apr 10 '17 at 09:15
  • Possible duplicate of [maven - read version number from property file](http://stackoverflow.com/questions/8541332/maven-read-version-number-from-property-file) – Mickael Apr 10 '17 at 09:42
  • For every time .we don't need to change the pom file . We need to change the particular updated property file instead of this . – user3518223 Apr 11 '17 at 04:48

1 Answers1

0

I suggest you to define the version of your application in a specific Maven project that you can use as parent Maven project.

From Maven documentation "Introduction to the POM" (Example 5) :

Example 5

The Scenario

Given the previous original artifact POMs again,

com.mycompany.app:my-app:1's POM

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
</project>

com.mycompany.app:my-module:1's POM

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-module</artifactId>
  <version>1</version>
</project>

and this directory structure

.
 |-- my-module
 |   `-- pom.xml
 `-- parent
     `-- pom.xml

The Solution

To do both project inheritance and aggregation, you only have to apply all three rules.

com.mycompany.app:my-app:1's POM

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
  <packaging>pom</packaging>

  <modules>
    <module>../my-module</module>
  </modules>
</project>

com.mycompany.app:my-module:1's POM

<project>
  <parent>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <version>1</version>
    <relativePath>../parent/pom.xml</relativePath>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-module</artifactId>
</project>

NOTE: Profile inheritance the same inheritance strategy as used for the POM itself.

Mickael
  • 4,458
  • 2
  • 28
  • 40
  • This is an excellent solution . But my requirement is to create a version config property in a porpetry file and access this in to my pom.xml – user3518223 Apr 10 '17 at 08:28
  • Is there any other solution to access my version property from an external property file into my pom.xml ? – user3518223 Apr 11 '17 at 04:52