Search code examples
maventycho

How to get the current build version in Maven/Tycho


I have read that the ${project.version} property should be used to obtain the full version of a project.

But if I use this property in a build to pass the currently built version to an external build process, its values is alway 1.0.0-SNAPSHOT where I would need something like 1.0.0-20160220-1234. The phase in which the external build step is called is `package´.

The tycho-packaging-plugin is configured to produce timestamps like this:

<configuration>
  <format>yyyyMMdd-HHmm</format>
</configuration>

And the resulting artifacts do have timestamps in the versions/names

I use Maven 3.3.3 with Eclipse Tycho 0.24, however, with previous versions of Tycho the behavior is the same. Not sure if Tycho behaves differently than plain Maven in this regard.

The build is run with

mvn clean verify

in the directory of the master pom.

The actual project I am using this for is Extras for Eclipse. The external build step is invoked in line 129 of the 'repository' child pom.

I have also used the echo plug-in in the above-mentioned child pom to diagnose the problem like this:

<plugin>
  <groupId>com.soebes.maven.plugins</groupId>
  <artifactId>maven-echo-plugin</artifactId>
  <version>0.1</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>echo</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <echos>
      <echo>actual version: ${project.version}</echo>
    </echos>
  </configuration>
</plugin>

The output is the same as the external build receives: 1.0.0-SNAPSHOT.

What do I need to do or which property do I need to use to get the qualified version of the current build?


Solution

  • From my understanding the ${project.version} property should hold the qualified version, e.g. 1.0.0-20160218-1234. But either there is a bug in Maven/Tycho or my understanding is plain wrong. And I would be happy if someone could clarify this.

    However, I found the ${qualifiedVersion} property that is set by the tycho-packaging:build-qualifier mojo. This property holds the expected value.

    Note that even though the documentation states

    is assigned to the project property qualifiedVersion

    the property cannot be accessed through ${project.qualifiedVersion}. It needs to be referenced as ${qualifiedVersion}.