[英]Add library dependencies to SBT, for SBT (not the project managed by SBT)
I am trying to create a Task for SBT, so when I type "deploy" the task creates a .jar and then deploys it via SCP (I need an SSH library). 我正在尝试为SBT创建一个任务,因此当我键入“ deploy”时,该任务将创建一个.jar,然后通过SCP进行部署(我需要一个SSH库)。 The problem I'm struggling with is that I don't know know to add a library dependency (an SSH library) for build.sbt itself.
我苦苦挣扎的问题是,我不知道要为build.sbt本身添加库依赖项(SSH库)。 I have
libraryDependencies += "org.apache.commons" % "commons-vfs2" % "2.2"
but this makes the library available to the project code, not the the SBT script "build.sbt" where I have to define the task. 我有
libraryDependencies += "org.apache.commons" % "commons-vfs2" % "2.2"
但这使该库可用于项目代码,而不是我必须在其中定义任务的SBT脚本“ build.sbt” 。
That sounds exactly like what's an sbt plugin ! 听起来完全像是sbt插件! Effectively a "sbt library".
有效地是“ sbt库”。
For example, maybe https://github.com/shmishleniy/sbt-deploy-ssh would be of help to you ? 例如,也许https://github.com/shmishleniy/sbt-deploy-ssh对您有帮助?
To use them, you'll need to edit the plugins.sbt
file, not the build.sbt
one 要使用它们,您需要编辑
plugins.sbt
文件,而不是build.sbt
文件。
For example, for this ssh one, you'll need to add to your plugins.sbt
file : 例如,对于这个ssh,您需要将其添加到
plugins.sbt
文件中:
resolvers += "JAnalyse Repository" at "http://www.janalyse.fr/repository/"
addSbtPlugin("com.github.shmishleniy" % "sbt-deploy-ssh" % "0.1.4")
You have two options: 您有两种选择:
First, if you plan to re-implement the same functionality in multiple projects, the best thing to do would be to create your own sbt plugin - it is basically just another scala project, thus you add the dependency in the build.sbt
of that project. 首先,如果您打算在多个项目中重新实现相同的功能,那么最好的办法是创建自己的sbt插件 -它基本上只是另一个scala项目,因此您可以在该
build.sbt
中添加依赖项项目。
Second, if you only need it for one project, and don't want to publish a plugin for it. 其次,如果您只需要一个项目,并且不想为其发布插件。 SBT is recursive that means you can modify the SBT used to manage your project.
SBT是递归的 ,这意味着您可以修改用于管理项目的SBT 。 This way you need to add your dependency to
./project/build.sbt
instead of ./build.sbt
- also I would recommend you write your task in a Scala file inside project
. 这样,您需要将依赖项添加到
./project/build.sbt
而不是./build.sbt
我也建议您将任务写在project
内的Scala文件中 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.