build.sbt 中的条件库 [英] Conditional libraries in build.sbt
本文介绍了build.sbt 中的条件库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 buildsbt.我正在尝试做这样的事情:
Using buildsbt. I'm trying to do something like this:
if (condition) {
libraryDependencies += ... // library from maven
}
else {
unmanagedJars in Compile += ... // local library instead
}
然而,build.sbt 根本不喜欢这个.我已经能够使用副作用来实现这一点,但这显然是不可取的.任何意见,将不胜感激.谢谢.
However, build.sbt doesn't like this at all. I've been able to accomplish this using side effects, but that's obviously undesirable. Any advice would be appreciated. Thanks.
推荐答案
您可以执行以下操作:
val additionalLibraryDependencies = Seq(...)
val additionalUnmanagedJars = Seq(...)
libraryDependencies ++=(
if (condition) {
additionalLibraryDependencies
}
)
unmanagedJars in Compile ++= (
if (!condition) {
additionalUnmanagedJars
}
)
要从命令行设置条件,您应该添加以下几行:
To set the condition from command line you should add the following lines:
val someValueFromCommandLine = System.getProperty("key.of.the.value", "false")
if (someValueFromCommandLine.equals("true")){
...
}
你可以像 sbt -Dkey.of.the.value=true
这篇关于build.sbt 中的条件库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文