有没有办法通过 sbt 插件获取项目的所有依赖项? [英] Is there a way to get all dependencies of the project via sbt plugin?

查看:42
本文介绍了有没有办法通过 sbt 插件获取项目的所有依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个 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?

推荐答案

在我们的项目中,我们使用更新任务来获取库依赖项:

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 */ }
}

希望这有助于开始.

以下是如何将此功能添加到您的任务的简单示例:

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) }
    }
))

要使用该任务,只需将 testSettings 添加到您的项目中即可.

To use the task just add testSettings to your project.

有关任务的更多信息,请参阅 sbt 文档.可以在此处找到有关更新任务的更多信息.

For more about tasks see the sbt documentation. More information about the update task can be found here.

更新任务仅获取库依赖项.我从未尝试过外部项目依赖项(如 git 存储库).也许您需要类似以下内容:查找项目工件.任务 allTheArtifacts 查找项目的工件及其项目依赖项的工件.

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.

这篇关于有没有办法通过 sbt 插件获取项目的所有依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆