code: public static Set<Dependency> getAllDependencies(final Module module, final List<String> producedArtifacts) {
          final Set<Dependency> dependencies = new HashSet<Dependency>();
  
          for(final Dependency dependency: module.getDependencies()){
              if(!producedArtifacts.contains(dependency.getTarget().getGavc())){
                  dependencies.add(dependency);
              }
          }
  
          for(final Module subModule: module.getSubmodules()){
              dependencies.addAll(getAllDependencies(subModule, producedArtifacts));
          }
  
          return dependencies;
      }
docs: Returns all the dependencies taken into account the artifact of the module that will be removed from the dependencies
  
  @param module Module
  @param producedArtifacts List<String>
  @return Set<Dependency>