0

I want to read the version that is used by the parent of my application. I try to write the version dynamically in the pom of the child.

Thank you for your suggestions.

Sudheesh Singanamalla
  • 2,283
  • 3
  • 19
  • 36
mourad
  • 369
  • 1
  • 3
  • 9
  • 1
    It's not clear what you mean by 'parent' and 'child'. Why do you want to do this? – Michael Jan 25 '18 at 16:32
  • you can read the parent's pom xml using Jaxb and then read the properties of the dependency section to read the values. – Apoorva sahay Jan 25 '18 at 16:32
  • This should help: https://stackoverflow.com/questions/3697449/retrieve-version-from-maven-pom-xml-in-code – tsolakp Jan 25 '18 at 17:06
  • Possible duplicate of [Retrieve version from maven pom.xml in code](https://stackoverflow.com/questions/3697449/retrieve-version-from-maven-pom-xml-in-code) – Tony Peterson Jan 25 '18 at 19:37

1 Answers1

1

You don't have to set version on a child pom since it inherits its parent version.

On the example below, the bar-child project inherits the 1.0 version attribute from it's parent bar:

<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>bar</artifactId>
    <version>1.0</version>
  </parent>

  <artifactId>bar-child</artifactId>
</project>

By the way, along the child pom configuration you can always type ${project.version} to reference the version number, which, as explained before, will be the same version as it's parent (1.0).

Check https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance for more information.

Rafael Odon
  • 1,211
  • 14
  • 20