Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

sbt

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?

like image 880
Rogach Avatar asked Feb 29 '12 07:02

Rogach


1 Answers

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.

like image 66
Christian Avatar answered Sep 29 '22 08:09

Christian