我目前正在尝试MANIFEST.MF在我的 build.sbt 中读取先前创建的 jar 并将此清单文件的属性用于packageOptions. 这样做的原因是我正在使用sbt-osgi插件创建一个 jar,然后想使用sbt-assembly创建一个胖 jar ,但保留之前创建的MANIFEST.MF.
到目前为止,这是我想出的:
import java.io.InputStream
import java.nio.file.StandardCopyOption
import java.util.jar.JarFile
import java.util.zip.ZipEntry
import sbt.Package.ManifestAttributes
import scala.collection.JavaConverters._
import scala.reflect.io.Directory
lazy val readManifestFromOSGiBundle = taskKey[Seq[(String, String)]]("Reads the MANIFEST.MF of the jar built by the OSGi plugin")
readManifestFromOSGiBundle in Compile := {
val uri = OsgiKeys.bundle.value
val jarFile = new JarFile(uri)
jarFile.getManifest.getMainAttributes.asScala.map(keyValue => (keyValue._1.toString, keyValue._2.toString)).toSeq
}
packageOptions := {
val manifestAttributes = readManifestFromOSGiBundle.value: Seq[(String, String)]
Seq(ManifestAttributes(manifestAttributes: _*))
}
清单属性已正确读取readManifestFromOSGiBundle,但不幸的是我无法弄清楚如何在我的packageOptions.
MMMHUHU
相关分类