Odd behavior when resolving configurations which have a dependency involving the module created by that build.gradle script

(chriswachter999) #1

I was trying to resolve a (tmp) configuration to get the paths of some uploaded artifacts (if there are better ways of answering the question ‘what did I just upload’, please tell me) and I found two unexpected behaviors.

1.) ResolvedDependency’s getModuleArtifacts() didn’t seem to want to return anything for the module from the current project 2.) Even though I was asking for a specific version, in the case of asking for the module from the current project, it insisted on returning the highest version available.

Using another external module dependency (i.e., not the product of the current build.gradle file) appears to work fine.

Here’s what I tried:

String t = new Date().getTime() as String
          def current = "method.training:gradleTest3:0.1.2"
// this module is what the build.gradle is producing; there is also a 0.1.3 available
        project.dependencies.add(t, current)
        current = "method.training:test1.cwachter:0.1.1"
// also tried an external module for comparasion
        project.dependencies.add(t, current)
          def spec = Specs.convertClosureToSpec { dep -> true }
        def testResult = project.configurations."$t".getResolvedConfiguration().getLenientConfiguration().getFirstLevelModuleDependencies(spec)
        println "========"
        if (testResult as boolean) {
            def artifacts = testResult.collect {
                println "${it}"
                println "${it.moduleArtifacts}"
                println "${it.moduleArtifacts.file}"
                println "--------"
            println "Resolved artifacts: $artifacts\n"

Which yielded:

[[ResolvedArtifact dependency:method.training:test1.cwachter:0.1.1;default name:install classifier:null extension:script type:install]]
file or directory '/home/cwachter/.gradle/caches/artifacts-14/filestore', not found
Resolved artifacts: [[[ResolvedArtifact dependency:method.training:test1.cwachter:0.1.1;default name:install classifier:null extension:script type:install]], []]

Again, this was really just to try to determine what was actually uploaded, but it seems like simply asking things like:

project.configurations."$t".files.each { println "resolved dependency: $it" }

for a configuration is a pretty straightforward/easily graspable general technique - it just doesn’t seem to work for the current build.gradle file’s module.

This was using 1.2

Thanks in advance, Chris

(Peter Niederwieser) #2

A lenient configuration skips what it can’t resolve. I guess it couldn’t find ‘method.training:gradleTest3:0.1.2’ in any repository. You can try and see what’s left in ‘getUnresolvedModuleDependencies()’.