0

I have a multi-module gradle project where in a module I add dependencies in compile configuration on runtime.

Those dependencies fetch a transitive dependency with a version prefix that does not exist.

So case is like this

compile 'group:moduleA:version.+'

This moduleA downloads moduleB with same version.+ prefix notation and that downloads another moduleC with same prefix notation, moduleC is present in artifactory with version 10 and above and 8 and below, so there are no versions which are number 9, and gradle insist on finding moduleC with version 9, it doesn't fetch versions above or below it.

How can I make gradle fetch another version if the version its trying to find is not there?

Please comment for any clarification and thanks for helping.

EDIT: Want to clarify that + in version part is not resolving to a number which is correct and present on artifactory, like 9.1 or 9.12.

gradle determines this version, which is incorrect like 9.1 is present but it resolves to 9.2 or some other number which is not there.

EDIT2: Task which is used to fetch dependencies and then add them in compile configuration.

task addAdditionalDependencies {
    doLast {
        Object slurper = new JsonSlurper().parseText(api.jsonResponse())
        Set<String> dependencyNames = configurations.compile.dependencies.collect { it.name }
        List<Map<String, String>> artifactPaths = slurper.results.collect {
            String[] pathSegments = it.path.split('/')
            if (!dependencyNames.contains(pathSegments[1]) && project.name != pathSegments[1]) {
                [group: pathSegments[0],
                 name: pathSegments[1],
                 version: "version.+",
                 configuration: 'compile']
            } else [:]
        }
        artifactPaths.each {
            if (!it.isEmpty()) {
                project.dependencies.add('compile', it)
            }
        }
        // we have to call this because app does not have any source files and so compileJava does not download
        // dependencies
        configurations.compile.files
    }
}
ateebahmed
  • 183
  • 5
  • 19

1 Answers1

0

When using a version like 9.+, Gradle will looks for all version that matches the prefix, that is the part before the +.

There is however no way to make Gradle ignore that part in case no such version exist.

If the version of moduleC can be anything, then you could simply use + without any prefix.

Note that doing something like that could expose you to breakage in a build even though nothing changed, aside from a new version of moduleC being published.

You could also combine this dynamic version resolution with dependency locking to have a finer grained control on when to upgrade moduleC.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43
  • Thanks for answering, I'll edit part of my question, I meant I want to control the part of `+`, the plus version is what's not working, because prefix is matching but there are many versions of suffix, which gradle determines itself. thing is gradle resolves `+` version in some number which doesn't exist and thus dependency fails. I hope I made it clear. – ateebahmed Jan 07 '20 at 11:30
  • That seems really strange. Any chance you can share you build file or parts of it? – Louis Jacomet Jan 08 '20 at 15:11
  • made an edit to add task which is adding dependencies in `compile` configuration on runtime – ateebahmed Jan 09 '20 at 12:41