gpt4 book ai didi

Scala SBT - sbt-native-packager,如何指定自定义阶段目录

转载 作者:行者123 更新时间:2023-12-04 17:59:03 25 4
gpt4 key购买 nike

如何为多项目配置指定自定义暂存目录?我正在使用 sbt-native-packager
下面是我的多模 block 配置的草图。当我上演这个项目( sbt stage )时,文件被写入

common/target/universal/stage
app1/target/universal/stage
app2/target/universal/stage

我想传递一个环境变量 stageSuffix像这样: sbt stage -DstageSuffix=XYZ .此变量应使其将项目暂存到以下目录:
common/target/universal/stage-XYZ
app1/target/universal/stage-XYZ
app2/target/universal/stage-XYZ

我试过修改 stagingDirectorycommonSettings ,但它并不完全有效,我收到诸如“对未定义设置的引用”之类的错误。

我怎样才能使这项工作?
val stageSuffix = sys.props.getOrElse("stageSuffix", ".")

val commonSettings = Seq(
stagingDirectory := stagingDirectory.value / stageSuffix, // this makes it fail
libraryDependencies ++= Seq(...))

val common = project.in(file("common"))
.enablePlugins(JavaAppPackaging)
.settings(commonSettings: _*)

val app1 = project.in(file("app1"))
.enablePlugins(JavaAppPackaging)
.settings(mainClass in Compile := Some("app1.Main"))
.dependsOn(common)
.settings(commonSettings: _*)
.settings(libraryDependencies ++= Seq(...))

val app2 = project.in(file("app2"))
.enablePlugins(JavaAppPackaging)
.settings(mainClass in Compile := Some("app2.Main"))
.dependsOn(common)
.settings(commonSettings: _*)
.settings(libraryDependencies ++= Seq(...))

val main = project.in(file("."))
.dependsOn(common, app1, app2)
.aggregate(common, app1, app2)
.settings(commonSettings: _*)

最佳答案

我设法让它像这样工作:

val stagingDirectoryOverrideOpt = sys.props.get("stageSuffix").map { stageSuffix =>
stagingDirectory in Universal := {
val stageFile = (stagingDirectory in Universal).value
new File(stageFile.getParentFile, s"stage-$stageSuffix")
}
}

val app1 = project.in(file("app1"))
.enablePlugins(JavaAppPackaging)
.settings(mainClass in Compile := Some("app1.Main"))
.dependsOn(common)
.settings(commonSettings: _*)
.settings(stagingDirectoryOverrideOpt.toSeq: _*)
.settings(libraryDependencies ++= Seq(...))

希望有办法让它更漂亮

关于Scala SBT - sbt-native-packager,如何指定自定义阶段目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37768156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com