如何更改 SBT 中 sbt-thrift 插件的默认设置? [英] How to change default settings of sbt-thrift plugin in SBT?

查看:45
本文介绍了如何更改 SBT 中 sbt-thrift 插件的默认设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sbt-thrift 插件 0.6 和 SBT 0.12 并且我需要更改构建配置中的资源目录、源目录、输出目录和其他设置.

I am using sbt-thrift plugin 0.6 with SBT 0.12 and I need to change the resource directory, source directory, output directory and other settings in my build configuration.

它似乎不像 README 中提到的那样工作.

It doesn't seem to work as mentioned in README.

谁能告诉我怎么做这件事?

Can someone tell me how to do this thing?

推荐答案

SBT 0.13 + sbt-thrift 0.7

注意以下是 SBT 0.12 和 sbt-thrift 0.6

SBT 0.13 + sbt-thrift 0.7

NOTE Below is the same configuration for SBT 0.12 and sbt-thrift 0.6

我使用 SBT 0.13.1,因此不得不使用 sbt-thrift 0.7 来自 http://bigtoast.github.io/repo/com/github/bigtoast/sbt-thrift_2.10_0.13/0.7/.

I use SBT 0.13.1 and hence had to use sbt-thrift 0.7 from http://bigtoast.github.io/repo/com/github/bigtoast/sbt-thrift_2.10_0.13/0.7/.

project/plugins.sbt

resolvers += "bigtoast-github" at "http://bigtoast.github.com/repo/"

addSbtPlugin("com.github.bigtoast" % "sbt-thrift" % "0.7")

build.sbt

import com.github.bigtoast.sbtthrift.ThriftPlugin

seq(ThriftPlugin.thriftSettings: _*)

有了上面的构建配置,你可能想看看https://github.com/bigtoast/sbt-thrift/blob/master/src/main/scala/ThriftPlugin.scala 可能的任务和设置(我没有检查是否 README.md 完全正确.

With the above build configuration, you may want to look at https://github.com/bigtoast/sbt-thrift/blob/master/src/main/scala/ThriftPlugin.scala for possible tasks and settings (I have not checked whether README.md's fully correct).

source-directory 设置用于设置thrift 文件的源目录.默认为 src/main/thrift".

> thrift:source-directory
[info] C:\dev\sandbox\thrift\src\main\thrift

要更改值,请使用以下内容:

To change the value use the following:

ThriftPlugin.thriftSourceDir := sourceDirectory.value / "my-own-source-dir"

reload 以便相应地更改设置(react):

and reload so the setting changes (react) accordingly:

> thrift:source-directory
[info] C:\dev\sandbox\thrift\src\my-own-source-dir\main\thrift

请注意,所有设置和任务都属于 thrift 配置.

Please note that all the settings and tasks belong to the thrift config.

project/plugins.sbt

resolvers += "bigtoast-github" at "http://bigtoast.github.com/repo/"

addSbtPlugin("com.github.bigtoast" % "sbt-thrift" % "0.6")

由于 OP 询问了多项目构建配置,下面是两个项目的定义,其中一个为 thriftSourceDir 配置了自定义值.

Since OP asked about multi-project build configuration, below is the definition of two projects with one configured with a custom value for thriftSourceDir.

project/MyBuild.scala

import sbt._
import Keys._
import com.github.bigtoast.sbtthrift.ThriftPlugin._

object MyBuild extends Build {
  lazy val thriftS = Defaults.defaultSettings ++
    thriftSettings ++
    Seq(
      thriftSourceDir <<= sourceDirectory(_ / "my-own-source-dir")
    )

  lazy val thriftP = Project("thriftProject", 
    file("."),
    settings = thriftS
  )

  lazy val someP = Project("some-other-project",
    file("some-other-project")
  )
}

通过构建配置,sbt shell 为您提供以下内容:

With the build configuration, sbt shell gives you the following:

> sbt-version
[info] 0.12.4
> projects
[info] In file:/Users/jacek/sandbox/so/thrift-0.12/
[info]     some-other-project
[info]   * thriftProject
> thrift:source-directory
[info] /Users/jacek/sandbox/so/thrift-0.12/src/my-own-source-dir/main/thrift
> thriftProject/thrift:source-directory
[info] /Users/jacek/sandbox/so/thrift-0.12/src/my-own-source-dir/main/thrift
> some-other-project/thrift:source-directory
[info] /Users/jacek/sandbox/so/thrift-0.12/some-other-project/src

这篇关于如何更改 SBT 中 sbt-thrift 插件的默认设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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