Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you inherit the version from the parent POM in Maven? [duplicate]

I have a bunch of projects like:

project1
project2
project3
........
project111

Each project compiled in jar: project-1.1.1.1.jar, .... Does it possible in parent folder add pom.xml so I can define version 1 time for all projects?

like image 296
user710818 Avatar asked Nov 06 '11 11:11

user710818


People also ask

What do child POM inherit from the parent POM?

Now child POM need to refer the parent POM using parent tag and specifying groupId/artifactId/version attributes. This pom file will inherit all properties and dependencies from parent POM and additionally can include extra sub-project specific dependencies as well.

Who do you inherit version from?

One copy is inherited from their mother (via the egg) and the other from their father (via the sperm). A sperm and an egg each contain one set of 23 chromosomes. When the sperm fertilises the egg, two copies of each chromosome are present (and therefore two copies of each gene), and so an embryo forms.

Can a Maven POM have 2 parents?

You can achieve multiple inheritance with profiles: This is not ideal because child projects cannot control the activation of profiles defined in the parent POM. This is not remotely related to inheritance. But you can use them to setup some parameters to turn on/off with a switch (enabling/disabling the profiles).

Are Maven properties inherited?

Maven supports project inheritance. You can create a parent project that contains properties child projects have in common, and child projects inherit those properties from the parent project.


2 Answers

If you omit <version/> it inherits from the parent. However, the <parent/> element must contain a <version/> for the parent, so the version must occur in every single POM, but only once.

like image 137
bmargulies Avatar answered Oct 19 '22 02:10

bmargulies


You can do this:

parent pom.xml:
<project>
  ...
  <version>${my-project-version}</version>
  ...
  <properties>
    <my-project-version>1.1.1</my-project-version>
  </properties>
</project>

child pom.xml:
<project>
  ...
  <parent>
    <relativePath>../parent/pom.xml</relativePath>
    <version>${my-project-version}</version>
  </parent>
  ...
</project>

At least, this works for me.

like image 25
Alexey Romanov Avatar answered Oct 19 '22 01:10

Alexey Romanov