DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • A Guide To Build, Test, and Deploy Your First DApp
  • What Is Ant, Really?
  • Test Automation: Maven Profiles and Parallelization in Azure Pipelines Using IaaS

Trending

  • 10 Predictions Shaping the Future of Web Data Extraction Services
  • Build Real-Time Analytics Applications With AWS Kinesis and Amazon Redshift
  • Squid Game: The Clean Code Trials — A Java Developer's Survival Story
  • Evaluating Accuracy in RAG Applications: A Guide to Automated Evaluation
  1. DZone
  2. Coding
  3. Java
  4. Stamping Version Number and Build Time in a Properties File with Maven

Stamping Version Number and Build Time in a Properties File with Maven

By 
Rob Terpilowski user avatar
Rob Terpilowski
·
Mar. 23, 12 · Interview
Likes (8)
Comment
Save
Tweet
Share
131.0K Views

Join the DZone community and get the full member experience.

Join For Free

Stamping the version number and the build time of an application in a properties file so that it could be displayed by an application at runtime seemed like it should be a pretty straightforward task, although it took a bit of time to find a solution that didn’t require the timestamp, version, or ant-run plugins.


I started with a version.txt file at the default package level in src/main/resources of my project, which looks as follows.

version=${pom.version}
build.date=${timestamp}

By default the Maven resources plug-in will not do text substitution (filtering), so it will need to be enabled within the <build> section of the pom.xml file.

<resources>
   <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
   </resource>
</resources>

Maven does actually define a ${maven.build.timestamp} property which in theory could have been used in the version.txt file, rather than the ${timestamp} property, but unfortunately a bug within Maven prevents the ${maven.build.timestamp} property from getting passed to the resource filtering mechanism. 


(issue:http://jira.codehaus.org/browse/MRESOURCES-99).


The workaround is to create another property within the pom.xml file and set that new property to the timestamp value, in this case, the property name is “timestamp”, which is used above in the version.txt file.  The maven.build.timestamp.format is an optional property for (obviously) defining the timestamp format.

<properties>
   <timestamp>${maven.build.timestamp}</timestamp>
   <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>

Now, when the build is executed we end up with the version number and build time of the application in the version.txt file. Easy!

version=1.0.2-SNAPSHOT
build.date=2012-03-16 15:42
Property (programming) Apache Maven Build (game engine)

Opinions expressed by DZone contributors are their own.

Related

  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • A Guide To Build, Test, and Deploy Your First DApp
  • What Is Ant, Really?
  • Test Automation: Maven Profiles and Parallelization in Azure Pipelines Using IaaS

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: