Can I set somehow IntelliJ building process to pre-process Java source codes and give me ever incrementing build number? Something like:
int myBuildNumber = INTELLI_J_IDEA_MAGIC_WHICH_WILL_INCREMENT_EVERY_BUILD;
In the top bar where File, Edit, View... Are written, go to the Help section. Click on Help section and in the drop-down click on About. That will show you the information regarding the Intellij Version you are using.
Ok so with hint from AtomHeartFather I got it.
First we need to write an ant xml file. This file will create file where build number will be stored and incremented and then it will look through your source code file ${src}/com/yourPath/Main.java
for variable public static final String BUILD_NUMBER = ".*";
and replace it with current build number
The xml file would look like this:
<project name="MyProject" default="init" basedir=".">
<description>
simple example increment build variable
</description>
<!-- set global properties for this build -->
<property name="src" location="../src"/>
<target name="init">
<echo file="myAntOut.txt">My first ant ${src} ${line.separator}</echo>
<buildnumber/>
<replaceregexp file="${src}/com/yourPath/Main.java"
match="public\s+static\s+final\s+String\s+BUILD_NUMBER\s+=\s+".*";"
replace="public static final String BUILD_NUMBER = "${build.number}";"
byline="true"
/>
</target>
</project>
Then in your intelliJ (I'm using 14.0.3) you click on View->Tool Windows->Ant Build
. Then +
and browse to your xml file (note that current path used by your xml will be the path to that xml file itself - not inteliJ project - thus you may want to correct the part location="../src"
depending on where you store your xml). Than you shall see our target init
you can select it and click play
button. If it works you shall see BUILD_NUMBER
incremented in you source code file Main.java
. Now the important trick how to make it automatically: Just right click on init
and select Execute on->Before Compilation
. Done :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With