-
Notifications
You must be signed in to change notification settings - Fork 1
/
deps.sbt
68 lines (62 loc) · 2.17 KB
/
deps.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sbt.*
import Keys.*
import scala.collection.mutable.ListBuffer
lazy val generateDeps =
taskKey[Unit]("Generates direct library dependencies of the project")
generateDeps := Def.taskDyn {
def formatAsMarkdownTable(
artifacts: Seq[(String, String, String, Option[String])]
): String = {
val header = "| Group ID | Artifact ID | Version |\n| --- | --- | --- |"
val rows = artifacts
.groupBy { case (groupId, artId, version, _) =>
s"| $groupId | $artId | $version |"
}
.keys
.toSeq
.sorted
(header +: rows).mkString("\n")
}
val projectRefs: Seq[ProjectRef] = loadedBuild.value.allProjectRefs.map(_._1)
val dependencies: ListBuffer[(String, String, String, Option[String])] =
ListBuffer.empty
Def
.sequential {
projectRefs
.map { projectRef =>
Def.task {
val allDeps =
(projectRef / libraryDependencies).value.sortBy(_.organization)
allDeps.map { dep =>
val configurations = dep.configurations
val res =
(dep.organization, dep.name, dep.revision, configurations)
dependencies.append(res)
res
}
}
}
}
.map { _ =>
val mainDeps = dependencies.filter(_._4.isEmpty).sortBy(_._1).distinct
val testDeps = dependencies.filter(_._4.nonEmpty).sortBy(_._1).distinct
val mainDepsTable = formatAsMarkdownTable(mainDeps)
val testDepsTable = formatAsMarkdownTable(testDeps)
val markdownContent = s"""# List of direct dependencies
|
|This document lists all direct dependencies of the project.
|
|## Main Libraries
|
|$mainDepsTable
|
|## Test Libraries
|
|$testDepsTable
|
|""".stripMargin
val file = new File("directDependencies.md")
IO.write(file, markdownContent)
()
}
}.value