2

I have the following pom definition (bottom).

I have many child poms (50 projects), requiring me to update all the poms on each release, for example, when moving from 1.0 to 1.1.

How can I define the version in a single place, and reuse it in all the poms?

EDIT- Some motivation about the request: I'd like to make as little footprint as possible when switching version. As little files to change. As little commits to push. Etc.

EDIT - Cannot use parent properties before the parent is loaded.

<parent>
    <groupId>info.fastpace</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<artifactId>child-1</artifactId>
AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277
  • I'm not aware of a shiny solution. There are a few things you can do, for example use ranges. See https://www.igorkromin.net/index.php/2015/11/08/getting-around-mavens-parent-child-project-version-dependency-issue/ which also has some insight on the maven plans. – wemu Jun 15 '16 at 11:18
  • 1
    You must be doing something wrong. The `maven-release-plugin` does that automatically (update POM versions) and should be used whe releasing the project. – Tunaki Jun 15 '16 at 11:23
  • @Tunaki - After the release, how do I update the version in the pom files? – AlikElzin-kilaka Jun 15 '16 at 11:24
  • You don't, the release does it by itself. It sets the POM to [`developmentVersion`](http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#developmentVersion). When you release 1.0-SNAPSHOT, you can configure the release plugin to change all version to 1.0 and have your working copy set to version 1.1-SNAPSHOT. – Tunaki Jun 15 '16 at 11:26
  • So I still need to commit 200 files to the source control. Still problematic. – AlikElzin-kilaka Jun 15 '16 at 11:30
  • 1
    Never use version ranges cause that will result in non reproducible builds. maven-release-plugin is one way or you can versions-maven-plugin...Only thing you need to be aware of is in maven-release-plugin for multi module project is to configure: `true`. Best in your parent. – khmarbaise Jun 15 '16 at 11:32
  • 1
    Of course you need to commit a change to your source/build ? If not how could make a reproduducible reference to it....Tagging the release state ? And why do you care about a 200 files which will be commited ? What is the problem? (Sure in case if you do that manually!). – khmarbaise Jun 15 '16 at 11:36

3 Answers3

2

I can use parent's properties and reference the parent using relative path instead of version. Example:

Parent:

<groupId>info.fastpace</groupId>
<artifactId>parent</artifactId>
<version>${global.version}</version>

<properties>
   <!-- Unique entry point for version number management --> 
   <global.version>1.0-SNAPSHOT</global.version>
</properties>

Child:

<parent>
    <groupId>info.fastpace</groupId>
    <artifactId>parent</artifactId>
    <version>${global.version}</version>
    <relativePath>..</relativePath>
</parent>

<artifactId>child-1</artifactId>

Disadvantage: Requires the parent pom to exist in the file system and make all developers use the same relative file structure.

See more info here.

Community
  • 1
  • 1
AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277
  • From here http://stackoverflow.com/questions/10582054/maven-project-version-inheritance-do-i-have-to-specify-the-parent-version – Fausto Carvalho Marques Silva Jun 15 '16 at 12:03
  • 1
    This is not a good idea nor it is needed. Better use versions-plugin or release plugin that's it. Or you have to use Maven 3.2.1 or greater which has support for that. [See release notes for Maven 3.2.1](http://maven.apache.org/docs/3.2.1/release-notes.html) – khmarbaise Jun 15 '16 at 13:05
  • @khmarbaise - feel free to post an answer. – AlikElzin-kilaka Jun 15 '16 at 13:09
0

You can use maven properties to build a single version numbering scheme. Like this:

<properties>
<my.version>1.1.2-SNAPSHOT</my.version>
</properties>

And then reference it like this:

<version>${my.version}</version>

Look here for more information: Maven version with a property

Community
  • 1
  • 1
-1

The use of properties is recommended when you have multiple dependencies of the same release. For example:

<project>
    ...
    <properties>
        ...
        <dep.jooq.version>3.7.3</dep.jooq.version>
        ...
    </properties>
    ...
    <dependencies>
        ...
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>${dep.jooq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>${dep.jooq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>${dep.jooq.version}</version>
        </dependency>
        ...
    </dependencies>
    ...
</project>

Instead, if you have to use the same dependency in different points in the POM file or if you are in module and you would use the same dependency version of the parent, I suggest to use the following way:

<project>
    ...
    <dependencyManagement>
        <dependencies>
            ...
            <dependency>
                <groupId>group-a</groupId>
                <artifactId>artifact-a</artifactId>
                <version>1.0</version>
            </dependency>
            ...
        <dependencies>
    </dependencyManagement>
    ...
    <dependencies>
        ...
        <!-- The following block could be in a module -->
        <dependency>
            <groupId>group-a</groupId>
            <artifactId>artifact-a</artifactId>
            <!-- It is no more ncessary to use the version -->
        </dependency>
        ...
    <dependencies>
    ...
</project>
sandromark78
  • 148
  • 1
  • 4
  • How does this solve the parent pom version raised issue? – AlikElzin-kilaka Jun 15 '16 at 13:40
  • In the POM file of the single module, you can specify the version of the dependency. When you will use the parent POM, the versions in the **dependencyManagement** will override the versions of the submodules. – sandromark78 Jun 15 '16 at 13:53