sbt compile tasks with different options

一曲冷凌霜 提交于 2019-12-08 03:07:59

问题


I have a basic sbt project. I want to package two jars with the same source files, but compilation with different options. So one project, 2 compilations but with different options (scalacOptions) and 2 jars as output. I don't want to execute sbt twice, changing the options.

Does anybody have an idea?


回答1:


With something like this in build.sbt, you can run sbt compile2:package and produce both a jar from the compile config and compile2 config:

val Compile2 = config("compile2") extend Compile

inConfig(Compile2)(Defaults.compileSettings ++ Seq(
    // these options can be set as "in Compile2" outside of inConfig as well
    scalacOptions := SECOND-OPTIONS-LIST,
    // otherwise it will be "src/compile2", you want it to be "src/main"
    sourceDirectory <<= sourceDirectory in Compile,
    sbt.Keys.`package` <<= sbt.Keys.`package` dependsOn (sbt.Keys.`package` in Compile)
))

scalacOptions in Compile := BASIC-OPTIONS-LIST

I guess this is relatively simple in terms of lines of code, but not quite so straightforward if one isn't intimately familiar with sbt.



来源:https://stackoverflow.com/questions/32520217/sbt-compile-tasks-with-different-options

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