【问题标题】:Add git commit id in fat jar manifest using sbt使用 sbt 在 fat jar manifest 中添加 git commit id
【发布时间】:2019-01-08 10:09:32
【问题描述】:

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

谢谢

【问题讨论】:

    标签: sbt sbt-assembly fatjar


    【解决方案1】:

    老问题,但我去...

    您可以使用带有 sbt-assembly 的 sbt-git 插件在您的 MANIFEST.MF 文件中包含 git 信息。

    要向您的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 生成的 fat jar 中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 2015-04-12
      • 2021-09-05
      • 1970-01-01
      • 2019-01-10
      • 2017-07-19
      • 2016-10-01
      相关资源
      最近更新 更多