简体   繁体   中英

Call hierachy of properties in pom.xml

I have a maven project with multiple nested projects. All of them do always have the same version. Untill now, if I want to increase the version, I went through all pom.xml files and changed the version number.

Now, I wanted to outsource the version to the properties tag of the parent pom.xml file. It works, for all nested projects, but not for the parent pom itself.

In which order are the attributes in the pom.xml called? I can not reference the project version in the parent pom.xml file.

The code snippet shows the parent pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <groupId>com.my.project</groupId>
    <artifactId>my.project</artifactId>
    <packaging>pom</packaging>
    <version>${projectVersion}</version>
    <properties>
        <projectVersion>1.0.0</projectVersion>
        ...
    </properties>
    <modules>
        <module>my.project.service</module>
        <module>my.project.db</module>
        ...
    </modules>

I expect the pom to take the version number defined in the properties. But it failes building with the error invalid reference format

I expect the pom to take the version number defined in the properties. But it failes building with the error invalid reference format

By running a maven goal from the parent project, maven first binds the artifact/group/version in the current build process, so it uses the version defined here : <version>${projectVersion}</version>

I can not reference the project version in the parent pom.xml file.

In this case, you could "cheat" by creating an aggregator/multimodule project that defines a not used/fake version ( 1.0-NOT-USED for example) that has as unique module the parent pom. When you build the aggregator/multimodule project, you can now pass as parameter the version to use in the parent project and all its modules.

As a side note, to use a central version for a set of projects, you should use the flatten maven plugin that relieves you from the hell version management.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM