如何向MANIFEST.MF添加自定义行?

时间:2014-05-08 15:46:14

标签: sbt manifest.mf

使用Build.scala向MANIFEST.MF添加自定义键值对似乎不起作用。这是我的代码:

import sbt._
import Keys._
import java.util.Date

object Build extends Build {

  packageOptions in (Compile, packageBin) +=
    Package.ManifestAttributes( "Build" -> "true" )

}

当我添加:

packageOptions in (Compile, packageBin) +=
  Package.ManifestAttributes( "Sign" -> "true" )

到我的build.sbt然后只有Sign到达我的MANIFEST.MF。有什么想法吗?

1 个答案:

答案 0 :(得分:7)

我想你可能想要这样的东西(注意manifestSettings添加到项目的设置中。)

import sbt._
import Keys._
import java.util.Date
import sbt.Package.ManifestAttributes

object MyBuild extends Build {

  lazy val manifestSettings = Seq(
    packageOptions in (Compile, packageBin) += 
         Package.ManifestAttributes( "Build" -> "true" )
  )

  lazy val root = Project(id = "root", base = file(".")).settings(manifestSettings: _*)

}

然后你应该能够调用package并拥有一个带有额外清单条目的jar。

修改

要获得("Buid" -> <current time>)manifestSettings应为

lazy val manifestSettings = Seq(
  packageOptions in (Compile, packageBin) += 
           Package.ManifestAttributes( "Build" -> new Date().toString() )
)