Search code examples
javamavenmaven-release-plugin

Ignore ${project.version} in Maven release:prepare


We have projects that are built one after another in the build server. They probably could become a multi-module project in the future, but at the moment there is no capacity for restructuring the repositories, projects etc. and introducing new parent POMs.

We tried to use a structure like

<?xml version="1.0" encoding="UTF-8"?>
<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">

  <modelVersion>4.0.0</modelVersion>

  <groupId>de.something</groupId>
  <artifactId>project1</artifactId>
  <version>9.0.2-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>de.something</groupId>
      <artifactId>project2</artifactId>
      <version>${project.version}</version>
    </dependency>

  </dependencies>

</project>

Unfortunately, the maven release plugin (more specifically, the release:prepare goal) fails on this because it considers the dependency to be a SNAPSHOT dependency.

Is there any way (besides rebuilding everything as multi-module) to tell the maven release plugin that this is not the case?

Something like

  • "${project.version} is ok, don't worry"
  • or "Don't check project2 for SNAPSHOT"

Solution

  • The "solution" is as follows:

    • define a property <dep.version>${project.version}</dep.version> in the POM and use it instead of ${project.version}.
    • Use the versions maven plugin to update the property ${dep.version} before the build to the next release version (and commit).
    • Do the build
    • Run the version plugin to reset the value ${dep.version} back to ${project.version}.