This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Putting a version number in source code

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a build process for a Java project which is part of a larger project containing Java and C++ code. I want the Java code to have access to a global version number. If I were doing this in C++ I'd compile it as "g++ -DVERSION=...", but that capability doesn't seem to exist in Java.

Instead, I'm implementing an Ant task as below. Is this the "correct" way of doing things? I haven't seen the <filter> task used this way in any of the documentation I've consulted so I'm a little concerned. I've also noticed that this won't remake the file if the version number changes. How do I get around this? Should I add a task that removes the generated file, that gets called from the scripts that build the full release?

My task is:




Thanks!
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Robert Miller:
Instead, I'm implementing an Ant task as below. Is this the "correct" way of doing things? I haven't seen the <filter> task used this way in any of the documentation I've consulted so I'm a little concerned.



Well, it's at least what we are doing, too...

I've also noticed that this won't remake the file if the version number changes. How do I get around this? Should I add a task that removes the generated file, that gets called from the scripts that build the full release?



Yes, deleting the generated file sounds like the right thing to do. I will to look what we are doing tomorow...
 
Saloon Keeper
Posts: 28074
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "depends" task can be used to indicate dependencies.
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic