How to deal with multiple version of a maven dependency?

With the following code:

dependencies {

compile “com.actividentity:activclient:6.2.0.86-FIXS1008016:x64@msp”

compile “com.actividentity:activclient:6.2.0.50:x64@msi”

}

Gradle always throws “Artifact ‘com.actividentity:activclient:6.2.0.86-FIXS1008016:x64@msi’ not found.”

I need to declare the dependency with multiple version above so that I can copy resources later.

Are you sure the artifact exists in a repo defined in your buildscript?

Try running with ‘–info’ and ‘–refresh-dependencies’ to see what requests Gradle is making and if they are what you expect.

Hi Luke,

I’m sure that those artifacts exists in the repo defined in my buildscript (if I remove a denpendency, the other one works well).

I think the problem here is that:

  • The version of the first dependency is 6.2.0.86-FIXS1008016 so when Gradle requests the second dependency (same groupId, same artifactId) , it will use that first version (6.2.0.86-FIXS1008016) instead of the second version (6.2.0.50).

Error log is :

Resource missing. [HTTP GET: REPO_URL/com/actividentity/activclient/6.2.0.86-FIXS1008016/activclient-6.2.0.86-FIXS1008016-x64.msi]

Thanks, Phuong.

This is a bug then. I’ve raised GRADLE-2428.

If you need them both in the same configuration, I’m unaware of a workaround.

What do you need to do with these dependencies once you have them?

I intend to copy or unzip to prepare for packaging WAR.

task extractPackages << {
    configurations.compile.each { File depFile
->
    println depFile.name
    if (depFile.name.endsWith('.msp') || depFile.name.endsWith('.msi')) {
        ant.copy(file: depFile, todir: 'build/resources/Packages')
    } else if (depFile.name.endsWith('.zip')) {
        ant.unzip(src: depFile, dest: 'build/resources/Packages') {
            patternset() {
                include(name: '**/*.manifest')
                include(name: '**/*.application')
                include(name: '**/*.msi')
                include(name: '**/*.exe')
            }
        }
    }
}

I know this is not good way. What else should we do here like maven-dependency-plugin (with goals : copy, unpack, …) ?

You can use two different configurations if you aren’t actually using these things to compile against.

// declare the configurations
configurations {
  msps
  msis
}
  dependencies {
   msps "com.actividentity:activclient:6.2.0.86-FIXS1008016:x64@msp"
   msis "com.actividentity:activclient:6.2.0.50:x64@msi"
 }
  task extractPackages << {
    (configurations.msps + configurations.msis).each { File depFile
->
    println depFile.name
    if (depFile.name.endsWith('.msp') || depFile.name.endsWith('.msi')) {
        ant.copy(file: depFile, todir: 'build/resources/Packages')
    } else if (depFile.name.endsWith('.zip')) {
        ant.unzip(src: depFile, dest: 'build/resources/Packages') {
            patternset() {
                include(name: '**/*.manifest')
                include(name: '**/*.application')
                include(name: '**/*.msi')
                include(name: '**/*.exe')
            }
        }
    }
}

Thank you very much, Luke. That is what I’m looking for.