Determining external vs sub-project dependencies


I wanted to determine a list of dependencies split into external dependencies and sub-project dependencies.
So far I have found a few ways to get the dependencies, but cannot figure a way to split between external and sub-project.

    task diag << {
        def configuration = project.configurations.runtime
        println("1: ${resolve1(configuration).collect { it.toString() }.sort()}")
        println("2: ${resolve2(configuration).collect { it.toString() }.sort()}")
        println("3: ${resolve3(configuration).collect { it.toString() }.sort()}")

private Iterable<ModuleVersionIdentifier> resolve1(Configuration config) {
        .findAll { DependencyResult result -> result instanceof ResolvedDependencyResult }
        .collect { ResolvedDependencyResult result -> } as Set

private Iterable<ModuleVersionIdentifier> resolve2(Configuration config) {
        .collect { ResolvedComponentResult component -> component.moduleVersion } as Set

private Iterable<ModuleVersionIdentifier> resolve3(Configuration config) {

private Iterable<ModuleVersionIdentifier> recurseDeps(Iterable<ResolvedDependency> deps) {
    def result = new HashSet()
    deps.each { ResolvedDependency dep ->

Could somebody please point me to the best way to determine which deps are external and which are sub-project?


1 Like

I have managed to get a bit further… this seems to work.

project.configurations.runtime.incoming.dependencies.each { Dependency dep ->
if (dep instanceof ExternalDependency) {
    ExternalDependency externalDependency = dep as ExternalDependency
    println("DEP EXTERNAL ${}:${}:${externalDependency.version}")

} else if (dep instanceof ProjectDependency) {
    ProjectDependency projectDependency = dep as ProjectDependency
    println("DEP PROJECT ${projectDependency}")

} else {
    println("DEP UNKNOWN ${dep}")

but does not include transitive dependencies. I also cannot figure how to convert a project dependency to a set of files.

What I am trying to do is - for each Java sub-project in a project:

  • get the list of maven descriptors (including transitive dependencies) that a sub-project requires; and
  • get the list of project jars that a sub-project requires (excluding anything fetched via maven repos).

Any assistance would be appreciated.

Finally figured something that works for what I wanted:

project.configurations.runtime.resolvedConfiguration.resolvedArtifacts.each { ResolvedArtifact artifact ->
def id =
if (id instanceof ProjectComponentIdentifier) {
    println("ARTIFACT FILE - ${artifact.file}")
} else if (id instanceof ModuleComponentIdentifier) {
    println("ARTIFACT MODULE ${}:${id.module}:${id.version}")
} else {
    println("ARTIFACT UNKNOWN ${artifact}")

Hopefully this is a reasonable way to get the relevant info.


1 Like