Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update version number in README.md during gradle build

I am working on an Android library (aar) project. The project contains a README.md file which in turn contains these lines:

   ... declare library dependency:

   Gradle: `compile 'com.acme:mylibrary:1.0.0@aar'`

My gradle.properties file contains:

VERSION_NAME=1.0.0

The problem is that currently I have to keep two files manually in sync. What I would like to do is keep the VERSION_NAME property and substitute it's value into README.md

like image 700
karel.herink Avatar asked Dec 20 '25 01:12

karel.herink


1 Answers

If you have some pattern to find out where you used the version number it could be as easy as creating a tasks and replacing text based on a regex.

Something like:

task replaceVersionInREADME << {
    // Maven
    ant.replaceregexp(match:'<version>([0-9\\.]+)</version>', replace:"<version>${version}</version>", flags:'g', byline:true) {
        fileset(dir: '.', includes: 'README.md')
    }
    // Gradle
    ant.replaceregexp(match:'com\\.acme\\:mylibrary\\:([0-9\\.]+)', replace:"com.acme:mylibrary:${version}", flags:'g', byline:true) {
        fileset(dir: '.', includes: 'README.md')
    }
}

Change the regex as you need.

like image 92
Luca Abbati Avatar answered Dec 22 '25 13:12

Luca Abbati