Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the next build number in Gradle

Tags:

java

gradle

ant

ivy

Is there any way to get the next version when publishing to a repository in gradle?

For e.g. if I have the version 3.0.1 in my repository I want the published version to be 3.0.2.

ivy has a task for ant named buildnumber which does exactly that:

<project xmlns:ivy="antlib:org.apache.ivy.ant"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <target name="ivyBuildNumber" description="Use ivy get the next build number">     <ivy:buildnumber         resolver="url-chain"         organisation="${ivy.organisation}"         module="${ivy.module}"         revision="${version.base}"/>      <echoproperties prefix="ivy.new."/> </target> 

Is there a way to do so in gradle? if not how can I access ivy tasks from gradle's ant?

In my build.gradle I calling to the ant

ant.importBuild 'build.xml' 
like image 472
Daniel Taub Avatar asked Nov 19 '17 07:11

Daniel Taub


2 Answers

I don't think there is support in Gradle, but you can try to use the Ant task. https://docs.gradle.org/current/userguide/ant.html#sec:import_ant_build

Another way to do this is to use some sort of plugin, or customized task for managing the version.

  • Plugin: https://github.com/researchgate/gradle-release
  • Custom task: https://www.tikalk.com/devops/increment-version-numbers-in-gradle/
like image 170
chenrui Avatar answered Oct 14 '22 19:10

chenrui


Yes, you can access ivy tasks from the ant script by importing ant's build.xml file to gradle's build.gradle file. Following is the syntax to do so.

ant.importBuild 'build.xml'

Please refer : https://docs.gradle.org/current/userguide/ant.html#sec:import_ant_build

like image 22
sricheta ruj Avatar answered Oct 14 '22 19:10

sricheta ruj