gpt4 book ai didi

scala - 如何在SBT中发布到多个存储库?

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

我正在升级 Nexus 版本。作为该过程的一部分,我设置了一个新的 Nexus 实例,它将与旧的 Nexus 实例并行运行。

在迁移到新实例时,我想在停止旧实例之前彻底测试和审查新实例。这需要我临时修改 publish 工作流程,以便 sbt 将工件发布到两个 Nexus 实例。

我非常怀疑下面的代码是否真的有效:

    publishTo <<= (version) {
version: String =>
if (version.trim.endsWith("SNAPSHOT")) Some("snapshots" at "http://maven1.dev.net:8081/nexus/content/" + "repositories/snapshots/")
else Some("releases" at "http://maven1.dev.net:8081/nexus/content/" + "repositories/releases/")
},
credentials += Credentials("Sonatype Nexus Repository Manager", "maven1.dev.net", "release-eng", "release"),

publishTo <<= (version) {
version: String =>
if (version.trim.endsWith("SNAPSHOT")) Some("snapshots" at "http://maven2.dev.net:8081/nexus/content/" + "repositories/snapshots/")
else Some("releases" at "http://maven2.dev.net:8081/nexus/content/" + "repositories/releases/")
},
credentials += Credentials("Sonatype Nexus Repository Manager", "maven2.dev.net", "release-eng", "release"),

我还尝试研究一个名为 sbt-multi-publish 的插件但我也无法编译和使用它。

最佳答案

CommandsHow to change a version setting inside a single sbt command?我可以定义一个新命令 - myPublishTo - 在执行原始 publish 任务之前更改 publishTo 设置:

def myPublishTo = Command.command("myPublishTo") { state =>
val extracted = Project.extract(state)
Project.runTask(
publish in Compile,
extracted.append(List(publishTo := Some(Resolver.file("file", target.value / "xxx"))), state),
true
)
Project.runTask(
publish in Compile,
extracted.append(List(publishTo := Some(Resolver.file("file", target.value / "yyy"))), state),
true
)
state
}

commands += myPublishTo

使用此命令,可以像任何其他命令/任务一样执行 myPublishTo

您还可以在 中定义几个别名 - pxxxpyyypxy >build.sbt 将使用 ; 执行一系列命令。

addCommandAlias("pxxx", "; set publishTo := Some(Resolver.file(\"file\", target.value / \"xxx\")) ; publish") ++
addCommandAlias("pyyy", "; set publishTo := Some(Resolver.file(\"file\", target.value / \"yyy\")) ; publish") ++
addCommandAlias("pxy", "; pxxx ; pyyy")

在 sbt 控制台中,您可以像执行任何其他命令/任务一样执行它们。

[sbt-0-13-1]> alias
pxxx = ; set publishTo := Some(Resolver.file("file", target.value / "xxx")) ; publish
pyyy = ; set publishTo := Some(Resolver.file("file", target.value / "yyy")) ; publish
pxy = ; pxxx ; pyyy
[sbt-0-13-1]> pxy
[info] Defining *:publishTo
[info] The new value will be used by *:otherResolvers, *:publishConfiguration
[info] Reapplying settings...
[info] Set current project to sbt-0-13-1 (in build file:/Users/jacek/sandbox/so/sbt-0.13.1/)
...
[info] published sbt-0-13-1_2.10 to /Users/jacek/sandbox/so/sbt-0.13.1/target/xxx/default/sbt-0-13-1_2.10/0.1-SNAPSHOT/sbt-0-13-1_2.10-0.1-SNAPSHOT-javadoc.jar
[success] Total time: 1 s, completed Jan 9, 2014 11:20:48 PM
[info] Defining *:publishTo
[info] The new value will be used by *:otherResolvers, *:publishConfiguration
[info] Reapplying settings...
...
[info] published sbt-0-13-1_2.10 to /Users/jacek/sandbox/so/sbt-0.13.1/target/yyy/default/sbt-0-13-1_2.10/0.1-SNAPSHOT/sbt-0-13-1_2.10-0.1-SNAPSHOT-javadoc.jar
[success] Total time: 0 s, completed Jan 9, 2014 11:20:49 PM

关于scala - 如何在SBT中发布到多个存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20985519/

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