sbt使用不同的选项编译任务

sbt使用不同的选项编译任务

本文介绍了sbt使用不同的选项编译任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的sbt项目。我想用相同的源文件包装两个jars,但使用不同的选项进行编译。
所以一个项目,2个编译,但有不同的选项(scalacOptions)和2个jars作为输出。我不想执行sbt两次,改变选项。

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.

有没有人有想法?

推荐答案

在build.sbt中这样的东西,你可以运行sbt compile2:package,并从编译配置和compile2配置生成一个jar:

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


b $ b

我猜这是相对简单的代码行,但不是很直接,如果一个人不熟悉sbt。

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.

这篇关于sbt使用不同的选项编译任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 15:56