使用 sbt 在 fat jar 清单中添加 git commit id [英] Add git commit id in fat jar manifest using sbt
问题描述
我正在使用 sbt-assembly 插件为我的 Scala 项目构建一个胖 Jar.有没有一种方法可以在 jar 清单中包含 git commit id,类似于 git-commit-id-plugin
为 maven 所做的事情.
I am using sbt-assembly plugin to build a fat Jar for my scala project. Is there a way I can include git commit id in the jar manifest, something similar to what git-commit-id-plugin
does for maven.
谢谢
推荐答案
老问题,但我去...
您可以使用 sbt-git 插件和 sbt-assembly 将 git 信息包含在您的MANIFEST.MF
文件.
You could use sbt-git plugin with sbt-assembly for including git information in your MANIFEST.MF
file.
要将信息添加到您的 MANIFEST.MF
文件,您可以这样使用 packageOptions
sbt 键:
For adding information to your MANIFEST.MF
file you can use the packageOptions
sbt key in this way:
import sbt.Package.ManifestAttributes
import com.typesafe.sbt.SbtGit.git
packageOptions := Seq(ManifestAttributes(("Repository-Commit", git.gitHeadCommit.value.get)))
参见此处的示例:spark-authorizer
此信息将存储在您的 MANIFEST.MF
文件中,该文件包含在 sbt-assembly 生成的 fat jar 中:
This information will be stored in your MANIFEST.MF
file included in the fat jar generated by sbt-assembly :
Manifest-Version: 1.0
Implementation-Title: spark-authorizer
Repository-Commit: 12538262c1be14800eb820163de6c46cdbd69c99
Implementation-Version: 0.1.0-SNAPSHOT
Specification-Vendor: de.example.playground.spark.authorizer
Specification-Title: spark-authorizer
Implementation-Vendor-Id: de.example.playground.spark.authorizer
Specification-Version: 0.1.0-SNAPSHOT
Implementation-Vendor: de.example.playground.spark.authorizer
您可以向 packageOptions
添加任意数量的值.所有这些都将包含在 MANIFEST.MF 文件中.
You can add as many values as you want to packageOptions
. All of them will be included in the MANIFEST.MF file.
这篇关于使用 sbt 在 fat jar 清单中添加 git commit id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!