Use of variable value inside the task and fetching all jar file


I am working on one gradle script and using gradle 2.3.I am able to read the version from file in my gradle script.I have one task below which basically untar the zip file but I am giving the hardcoded value of zip file.How could I use the value of version variable inside that task.

  1. I am fetching the jar files from artifactory in below manner but it is fetching only the top version of the jar file e.g. if foo is having 1.0 & 1.2 it is fetching only 1.2 jar file.Please let me know what is the issue

    apply plugin: 'java’
    apply plugin: ‘base’

    //-- set the group for publishing
    group = ‘com.truvenhealth.carediscovery’


    • Initializing GAVC settings
      def buildProperties = new Properties()
      file(“”).withInputStream {
      stream -> buildProperties.load(stream)
      //add the jenkins build version to the version
      def env = System.getenv()
      if (env[“BUILD_NUMBER”]) buildProperties.carediscoveryadBuildVersion += "_${env[“BUILD_NUMBER”]}"
      version = buildProperties.carediscoveryadBuildVersion
      println “${version}”

    //name is set in the settings.gradle file
    group = "com.truvenhealth.carediscovery"
    version = buildProperties.carediscoveryadBuildVersion
    println “Building ${}:${}”

    repositories {
    maven {
    url “

    dependencies {
    runtime ""
    runtime ""
    runtime “”

    task copyDeps(type: Copy) {
    from configurations.runtime
    into ‘services/carediscovery/services/’

    task deletebuild(type: Delete, dependsOn: copyDeps){
    def dirNamebuild = "/build/"
    delete dirNamebuild

    task buildreportZip(type: Zip, dependsOn: deletebuild) {
    from(‘data’) {
    into ‘data’

     from('sql') {
         into 'sql'
     from('services') {
         into 'services'


    task deleteGraphicsAssets(type: Delete, dependsOn: buildreportZip) {
    def dirName = "/applications/repositories/application-data/"
    delete dirName

     doLast {


    task unzip(type: Copy, dependsOn: deleteGraphicsAssets) {
    version = buildProperties.carediscoveryadBuildVersion
    println “${version}“
    def zipFile = file(‘build/distributions/’)
    def outputDir = file(”/applications/repositories/application-data/”)
    from zipTree(zipFile)
    into outputDir
    dirMode 0755

    // for publishing to artifactory
    artifacts {
    archives buildreportZip

To answer the first question, you can handle that in afterEvaluate.

project.afterEvaluate { Project p-> 
  p.dependencies {
    runtime "${p.version}@jar"

Writh respect to the second question, it is expected behaviour. Here’s your RTFM -