Reputation: 552
Currently, every time the source in my ant project is built a java file with a static final variable with the version number is generated. The version number is formatted as yyyyMMdd
so that it is always increasing. My problem is that I'm currently checking in the resulting build jar into source control (which I view as a failure, since I don't believe that I should be checking in binaries that are created from the build process).
I was wondering if there was an easy way to generate and write a date based version number to a java file in gradle before compilation, and also if there was a way to somehow only regenerate this version number when I'm building in development and not when someone else is going to rebuild the same version from source. It's a difficult separation of tasks, but I'm hoping someone has had some experience with it before.
Upvotes: 0
Views: 117
Reputation: 84884
You are correct when it comes to not include binaries into source control - of course some type of binaries - I mean, the output of compilation.
Basically modifying sources by build tools is not a good practice, it may cause many problems. Instead, I suggest to add a plain old properties file that will be filtered during build and an entry within it will be substituted with the current date. This file will be included into the binary output of compilation (namely jar file) but can be ignored in source control since it's irrelevant.
What are you asking about can be done in gradle, however it's not a good idea (as I mentioned).
Upvotes: 1