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

Hi

I am working on one gradle script and using gradle 2.3.I am able to read the version from version.properties 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(“version.properties”).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 ${project.group}:${project.name}”

    repositories {
    maven {
    url “http://cmxxx2art.tsh.thomson.com:8070/artifactory/services-release-local
    }
    }

    dependencies {
    runtime "carediscovery.services:PublishOpportunityReadService:1.1@jar"
    runtime "carediscovery.services:PublishedOpportunityReadService:1.1@jar"
    runtime “carediscovery.services:AnalysisListService:1.0@jar”
    }

    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 {
         file(dirName).mkdirs()
     }
    

    }

    task unzip(type: Copy, dependsOn: deleteGraphicsAssets) {
    version = buildProperties.carediscoveryadBuildVersion
    println “${version}“
    def zipFile = file(‘build/distributions/cdad-03_00_00_131.zip’)
    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 "carediscovery.services:PublishOpportunityReadService:${p.version}@jar"
 }
}

Writh respect to the second question, it is expected behaviour. Here’s your RTFM - https://docs.gradle.org/current/userguide/dependency_management.html