Dean Hiller
Dean Hiller

Reputation: 20182

how to handle versions in maven?

I have all these version numbers throughout parent pom and children poms including the parent reference like so

  <parent>
     <groupId>com.cigna.ifp</groupId>
     <artifactId>ifp-core</artifactId>
     <version>${parent.version}</version>
  </parent>

and dependency references to other child projects like so

<dependency>
  <groupId>com.cigna.ifp</groupId>
  <artifactId>ifp-shared</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>

and finally the declaration of the version of the thing we are building

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company</groupId>
  <artifactId>artifcat</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>ifp-shared</name>
  <url>http://maven.apache.org</url>

EDIT based on some answers which solved half the question...

We want to have all the versions be ${project.version} since it is really just one project with one release number.

I can seem to do ${project.version} in the dependency but this does not work in the parent xml code above. Is there another way? (man, I should really just switch to gradle).

thanks, Dean

Upvotes: 1

Views: 903

Answers (4)

Dean Hiller
Dean Hiller

Reputation: 20182

We switched to gradle which works fabulously now. Every automated build a new version is released as 1.2.x where x is the next build number. Downstream, projects depend on 1.2.+. This allows every release to be official so QA can test it, reject it or go, yup, build 1.2.568 is the release we will release to the world. Projects can depend on 1.2. but then they don't get bug fixes. This seems to work much better than all that snapshot nonsense as you give QA a snapshot and they approve and you have to change and do another build. We want every build to look official so they can release the one that happens to pass all QA tests.

Upvotes: 0

fmucar
fmucar

Reputation: 14548

You need to use dependencyManagement tag to centerilize the versions in the parent pom for the dependencies.

See this question and answers

differences between dependencymanagement and dependencies in maven

For you your own modules, some of the properties are inherited from the parent pom. You will need to declare the parent version in each child but you don't need to declare a groupId/version in your child poms if you want them to be same as their parent's.

Upvotes: 0

ptyx
ptyx

Reputation: 4164

<parent>
 <groupId>com.cigna.ifp</groupId>
 <artifactId>ifp-core</artifactId>
 <version>1.2.3-SNAPSHOT</version> <!-- real version-->
</parent>

<artifactId>blah</artifactId>
<!-- No version here, will be inherited -->

<dependency>
  <groupId>com.cigna.ifp</groupId>
  <artifactId>ifp-shared</artifactId>
  <version>${project.version}</version>
</dependency>

Upvotes: 1

Andrew T Finnell
Andrew T Finnell

Reputation: 13628

project.version is what you want. Not parent.version.

Upvotes: 0

Related Questions