task dependencyPlot { doLast {
  def includeTest = false
  def includeExternal = false
  def depsExclude = [ rootProject.path, ":elki-bundle" ]
  def projs = rootProject.subprojects.findAll { !depsExclude.contains(it.path) }.sort()
  new File("dep.dot").withWriter { out ->
    out.println "digraph dependencies {"
    out.println "graph[rankdir=TB,nodesep=.25,ranksep=.25,ratio=compress,margin=0];"
    out.println "node[shape=box,margin=.05,height=0,width=0];"

    // External dependencies, nodes:
    if (includeExternal)
      projs.collectMany {
        Project p -> p.configurations.compileClasspath.allDependencies }.findAll {
        !(it instanceof ProjectDependency) }.unique().sort().each { dep ->
        def n = "${dep.group}:${dep.name}"
        out.println "\"${n}\" [label=\"${dep.group}\\n${dep.name}\",color=blue,fontcolor=blue];"
      }
    // Internal depdenencies, nodes:
    projs.each { dep ->
      def n = "${dep.group}:${dep.name}"
      out.println "\"${n}\" [label=\"${dep.name}\"];"
    }

    projs.each { Project p ->
      def s = "${p.group}:${p.name}"
      // p.configurations.all.collectMany { con -> con.allDependencies }.unique().each { dep ->
      def seen = new HashSet()
      p.configurations.compile.allDependencies.each { dep ->
        def t = "${dep.group}:${dep.name}"
        if(seen.add(t) && (dep instanceof ProjectDependency || includeExternal)) {
          out.println "\"${s}\" -> \"${t}\";"
        }
      }
      p.configurations.testCompile.allDependencies.each { dep ->
        def t = "${dep.group}:${dep.name}"
        if(seen.add(t) && includeTest && (dep instanceof ProjectDependency || includeExternal)) {
          out.println "\"${s}\" -> \"${t}\" [color=grey];"
        }
      }
    }

    out.println "}"
  }
} }
