Andrey Rikunov
Andrey Rikunov

Reputation: 115

Maven - how to get build date time of an artifact?

Is there a way to display build date time of an artifact using mvn cli?

Context: Say I have a dependency with version eq RELEASE (Maven downloads latest release version of such an artifact for every build) and need to know its build date and time.

Upvotes: 1

Views: 4793

Answers (3)

Felix Aballi
Felix Aballi

Reputation: 949

Declare pom's property:

<maven.build.timestamp.format>yyyy/MM/dd HH:mm:ss</maven.build.timestamp.format>

or chosen date format.

Then using resources filtering or placing in src/main/resources a file:

Example

BuildInfo.properties

buildDate=${buildDate}

Upvotes: 0

Olivier Gr&#233;goire
Olivier Gr&#233;goire

Reputation: 35417

If the build was performed with maven and you're not responsible for it, you can check in the jar's META-INF/maven/<groupId>/<artifactId>/pom.properties.

It's possible though that this information is missing due to specific plugins, maven versions, etc.

I do not recomment using this technique to automatically extract information. This is good if it's a one-of, without guarantees of success.

The content of the pom.properties is like the following:

#Generated by Maven
#Fri Aug 07 17:02:37 CEST 2015
version=0.0.1-SNAPSHOT
groupId=be.ogregoire
artifactId=tets

What interests you is the 2nd line. But as it is commented, don't use a Properties object to read it.

Also, I admit I don't know any cli way to check this.

Upvotes: 2

psliwa
psliwa

Reputation: 1092

This plugin should solve your requirement. You can use it like this:

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>create</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <doCheck>true</doCheck>
          <doUpdate>true</doUpdate>
        </configuration>
      </plugin>
    </plugins>
  </build>

afterwards you'll be able to modify the final name, i.e.

  <build>
    <finalName>$\{project.artifactId}-$\{project.version}-r$\{buildNumber}</finalName>
  </build>

similarly, in order to use a date of a build within your POM, take advantage of buildnumber:create-timestamp.

Upvotes: 2

Related Questions