Get transitive dependency objects from configuration

Hello everyone!

I have a configuration called shadowRelocate. Since I want to relocate them with the shadow plugin I wrote this little code:

shadowJar {
    from sourceSets.main.output
    from mainDirResources

    classifier = null
    version = jar.version
    configurations = [project.configurations.shadow]

    doFirst {
        project.configurations.shadowRelocate.dependencies.each {
            relocate(it.group, "${project.group}.shadow.${it.group}")
        }
    }
}

The only issue is that that doesn’t include transitive dependecies, which should be relocated too.

So I tried project.configurations.shadowRelocate.incoming.resolutionResult.allDependencies.each. However, since getAllDependencies doesn’t return a set of Dependcies but rather resolved dependencies, the method getGroup is unknow and my code naturally doesn’t work.

project.configurations.shadowRelocate.resolvedConfiguration.resolvedArtifacts.each didn’t work either. Has anyone an idea how I can realize this?

I still haven’t managed to get it working. I’m aware that I can still manually relocate everything though I’d like to automate this process.

You will need to use something like:

project.configurations.shadowRelocate.incoming.resolutionResult.allComponents {
  if (it.id instanceof ModuleComponentIdentifier) {
    relocate(it.id.group, "${project.group}.shadow.${it.id.group}")
  }
}

Thank you so much! That is actually the solution!