Is there a way to get all dependencies of the project via sbt plugin?

给你一囗甜甜゛ 提交于 2020-01-13 02:44:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!