问题
I want to write an sbt plugin, and inside it I need to get the list of all dependencies of current project (with some info, is possible). Is it possible?
回答1:
In our project we use the update task to get the library dependencies:
(update) map {
(updateReport) =>
updateReport.select(Set("compile", "runtime")) foreach { srcPath => /* do something with it */ }
}
Hope this helps for a start.
[EDIT] Here is a simple example how to add this functionality to your task:
val depsTask = TaskKey[Unit]("find-deps", "finds the dependencies")
val testConf = config("TestTasks") hide
private lazy val testSettings = inConfig(testConf)(Seq(
depsTask <<= (update) map {
(updateReport) =>
updateReport.select(Set("compile", "runtime")) foreach { srcPath => println("src path = " + srcPath) }
}
))
To use the task just add testSettings to your project.
For more about tasks see the sbt documentation. More information about the update task can be found here.
[EDIT2] The update task only gets the library dependencies. I never tried out external project dependencies (like to a git repository). Maybe you need something like the following: find project artifacts. The task allTheArtifacts finds the artifacts of the project and the artifacts of its project dependencies.
来源:https://stackoverflow.com/questions/9494872/is-there-a-way-to-get-all-dependencies-of-the-project-via-sbt-plugin