问题
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