How to change default settings of sbt-thrift plugin in SBT?

♀尐吖头ヾ 提交于 2019-12-08 11:50:07

问题


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.

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

Can someone tell me how to do this thing?


回答1:


SBT 0.13 + sbt-thrift 0.7

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

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: _*)

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

There's source-directory setting to set "Source directory for thrift files. Defaults to 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"

and reload so the setting changes (react) accordingly:

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

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

SBT 0.12 + sbt-thrift 0.6

project/plugins.sbt

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

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

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

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


来源:https://stackoverflow.com/questions/21825063/how-to-change-default-settings-of-sbt-thrift-plugin-in-sbt

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