gradle Auto Increment Version Number Using Gradle Script For Android Applications Read and Assign Version Number from a property file to a variable


def versionPropsFile = file('') def versionBuild

/*Setting default value for versionBuild which is the last incremented value stored in the file */
if (versionPropsFile.canRead()) {
    def Properties versionProps = new Properties()
    versionProps.load(new FileInputStream(versionPropsFile))
    versionBuild = versionProps['VERSION_BUILD'].toInteger()
} else {
    throw new GradleException("Could not read!")