0

I am trying to fetch all the version of single dependency from the artifactory through my gradle script.The issue is gradle only fetch the latest version of the dependency and that is causing an issue with my applcation.whereas I am able to do the same in maven.Why gradle is not fetching all the version of that dependency.Below is the example

dependencies {
    runtime "carediscovery.services:GenericServices:1.0@jar"
    runtime "carediscovery.services:GenericServices:1.1@jar"
    runtime "carediscovery.services:GenericServices:1.2@jar"
    runtime "carediscovery.services:GenericServices:1.3@jar"
    runtime "carediscovery.services:GenericServices:1.5@jar"
    runtime "carediscovery.services:GenericServices:1.6@jar"
    runtime "carediscovery.services:LoadPathways:1.0@jar"
    runtime "carediscovery.services:LoadPathways:1.1@jar"
}

Gradle script is fetching only 1.6 version for GenericServices.

Can someone tell me is there anyway to fetch all the dependencies from 1.0...1.6 in gradle?

I tried the below code but this is giving me the error can someone tell why it is giving me this

apply plugin: 'java'


  repositories {
    maven {
      url "http://cm.t.thn.com:8/artifactory/services-release-local"
    }
  }


    def deps = [GenericServices: (0..6), LoadPathways: (0..1)]

    deps.each { dep, version ->
        configurations.create("$dep$version")
        dependencies.add("$dep$version", "carediscovery.services:$dep:1.$version@jar")
    }

    task copy(type: Copy) {
        from(deps.collect { dep -> dep.value.collect { configurations."$dep.key$it" } }.flatten())
        into 'services/carediscovery/services'
    }

Below is the error results

**C:\NEW_HG_WORKSPACE\APPLICATION-DATA>gradle clean build

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\NEW_HG_WORKSPACE\APPLICATION-DATA\build.gradle' line: 20

* What went wrong:
A problem occurred evaluating root project 'application-data'.
> Could not find property 'GenericServices0' on configuration container.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

BUILD FAILED**

I fixed the above issue and it is working fine now

apply plugin: 'java'


      repositories {
    maven {
      url "http://c.t.t.com:8/artifactory/services-release-local"
    }
  }


    def deps = [GenericServices: (0..6), LoadPathways: (0..1)]

    deps.each { dep, versions -> 
    versions.each { version -> 
        configurations.create("$dep$version")
        dependencies.add("$dep$version", "carediscovery.services:$dep:1.$version@jar")
    }
} 

    task copy(type: Copy) {
        from(deps.collect { dep -> dep.value.collect { configurations."$dep.key$it" } }.flatten())
        into 'services/carediscovery/services'
    }
unknown
  • 1,815
  • 3
  • 26
  • 51
  • Gradle resolves to the latest dependency defined so there will not be duplicates on the classpath (Maven does this too). In Gradle this is scoped to a configuration, so you need one per version. – Ben Manes Jul 10 '15 at 05:00
  • 2
    Why do you want to get all versions of a dependency? Surely you only want your application to use a single version? – Alex Jul 10 '15 at 09:38
  • 1
    In maven to copying specific artifacts, you need to bind the dependency:copy mojo to a lifecycle, configure the plugin and specify the artifacts you want to copy. – unknown Jul 10 '15 at 14:07
  • @Alex In my case, I want to do the same. I want all the versions of a given artifact (ex: all versions of this between: my.company.com:myartifact:1.0.1 and my.company.com:myartifact:2.5.0) inside a custom zip file. – AKS Jul 16 '15 at 20:41

0 Answers0