使用sbt在Fat jar清单中添加git commit id

时间:2018-07-31 22:41:16

标签: sbt sbt-assembly fatjar

我正在使用sbt-assembly插件为我的scala项目构建一个胖的Jar。有什么办法可以在jar清单中包含git commit id,类似于git-commit-id-plugin对maven所做的事情。

谢谢

1 个答案:

答案 0 :(得分:0)

老问题,但是我去...

您可以将sbt-git插件与sbt-assembly一起使用,以将git信息包括在MANIFEST.MF文件中。

要向您的MANIFEST.MF文件中添加信息,您可以通过以下方式使用packageOptions sbt键:

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生成的胖子存储中:

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文件中。