Include-build: How to get substituted project dependencies?

plugins

(Pascal Wölfle) #1

Hello everyone,

currently we want to introduce an include-build in our development process. We have some own gradle plugins that must distinguish between ProjectDependency and ExternalDependency.

Project project = ...
ConfigurationContainer configurations = project.getConfigurations();
Configuration runtimeConfiguration = configurations.getByName("runtime");    

ResolvedConfiguration resolvedConfiguration = runtimeConfiguration.getResolvedConfiguration();
DomainObjectSet<Dependency> dependencies = runtimeConfiguration.getAllDependencies().withType(Dependency.class);

for (Dependency dependency : dependencies) {
  if (dependency instanceof ProjectDependency) {
     doSomethingWithProjectDependency((ProjectDependency) dependency);
  } else if (dependency instanceof ExternalDependency) {
    doSomethingWithExternalDependency((ExternalDependency) dependency);
  }
}

Using include-build, our expectation is that each substituted dependency would be a ProjectDependency, but it is still a ExternalDependency.

What are we doing wrong?

Thanks for any advice :slight_smile:


(Stefan Oehme) #2

This code is querying the unresolved dependencies (i.e. what the user requested). Dependency substitution is only visible on the resolved dependency graph:

configuration.incoming.resolutionResult.allDependencies {
 if (from.id instanceOf ProjectComponentIdentifier) {
  //do something with a project dependency
 }
}

(Pascal Wölfle) #3

Thank you @st_oehme this solved my problem.