设置sbt发布到基于git分支的artifactory [英] Setting up sbt to publish to artifactory based on git branch
问题描述
我想建立一个sbt项目,以便它可以基于(git)分支发布到适当的artifactory存储库。
I would like to set up an sbt project so that it can publish to the proper artifactory repository based on the (git) branch.
一个href =https://stackoverflow.com/questions/33091153/can-sbt-publish-to-jfrog-artifactory>这个问题建议硬编码build.sbt文件中的存储库。
The solution proposed for this question suggests to hardcode the repository in the build.sbt file.
然而,我希望master分支发布到发布,另一个分支发布到快照,使用相同的build.sbt文件。
However, I would like the master branch to publish to "releases", and another branch to publish to "snapshots", using the same build.sbt file.
理想情况下,我希望以下内容:
Ideally, I would like the following:
val gitBranch = taskKey[String]("Determines current git branch")
gitBranch := Process("git rev-parse --abbrev-ref HEAD").lines.head
publishTo := {
val myArtifactory = "http://some.where/"
if (gitBranch.value == "master")
Some("releases" at myArtifactory + "releases")
else
Some("snapshots" at myArtifactory + "snapshots")
}
但这会产生错误:设置不能依赖任务。
but this yields "error: A setting cannot depend on a task".
推荐答案
一个接近解决方案是使用 sbt-release
插件,然后使用 isSnapshot
(这是一个设置)以选择存储库。
One near-solution is to work with the sbt-release
plugin, and then to use isSnapshot
(which is a setting) in order to select the repository.
原始问题的解决方案是简单地将 gitBranch
设置为一个设置:
The solution to the original problem is to simply make gitBranch
a setting:
val gitBranch = settingKey[String]("Determines current git branch")
而非
instead of
val gitBranch = taskKey[String]("Determines current git branch")
请注意,设置仅计算一次,在sbt会话开始时,如果在会话中有任何分支交换,这是不合适的。
Note that a setting is only computed once, at the beginning of the sbt session, so this is not suitable if there is any branch-switching within a session.
这篇关于设置sbt发布到基于git分支的artifactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!