为了账号安全,请及时绑定邮箱和手机立即绑定

使用 SBT 从另一个 jar 中读取 ManifestAttributes

使用 SBT 从另一个 jar 中读取 ManifestAttributes

米琪卡哇伊 2022-07-27 09:53:36
我目前正在尝试MANIFEST.MF在我的 build.sbt 中读取先前创建的 jar 并将此清单文件的属性用于packageOptions. 这样做的原因是我正在使用sbt-osgi插件创建一个 jar,然后想使用sbt-assembly创建一个胖 jar ,但保留之前创建的MANIFEST.MF.到目前为止,这是我想出的:import java.io.InputStreamimport java.nio.file.StandardCopyOptionimport java.util.jar.JarFileimport java.util.zip.ZipEntryimport sbt.Package.ManifestAttributesimport scala.collection.JavaConverters._import scala.reflect.io.Directorylazy 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.
查看完整描述

1 回答

?
MMMHUHU

TA贡献1834条经验 获得超8个赞

循环依赖是由调用OsgiKeys.bundle.valueinside引起的readManifestFromOSGiBundle。我用这条线替换artifactPath.in(packageBin).in(Compile).value了它,现在它可以工作了。



查看完整回答
反对 回复 2022-07-27
  • 1 回答
  • 0 关注
  • 89 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信