How to create a basic project setup using sbt-nati

2019-07-19 15:51发布

问题:

I have a project setup working with SBT to the point of creating sub-project artifacts.

I have been searching for a way to create a JAR file that contains sub-project JAR files along with some meta information. Based on suggestions, I looked at sbt-native-packager and it seems to have the capabilities I need.

I am wondering if someone would be willing to help me along this path by providing tips on creating a skeleton package specification for the plugin.

I think my configuration is pretty simple.

What I want to end up with is a JAR file with the following contents:

/manifest.xml
 module.xml
 modules/sub-project-one.jar
         sub-project-two.jar
         sub-project-three.jar

Both the manifest.xml and module.xml files will be generated from project information. The name of the resulting JAR file will be based on the name of the root project, it's version and a suffix "nkp.jar" (e.g. overlay-1.0.1.nkp.jar).

Thanks in advance for any help getting me going with this.

-- Randy

回答1:

Here's the basics of what you want:

val createManifestXml = taskKey[File]("Creates the packaged maniest.xml")

val createModuleXml = taskKey[File]("Creates the module.xml file.")

// TODO - Define createManifestXml + createModuleXml

mappings in Universal ++= {
   Map(createManifestXml.value -> "manifest.xml"
      module.xml -> "module.xml")
}

mappings in Universal ++= {
   val moduleJars = 
      Seq((packageBin in subProjectOne).value, 
          (packageBin in subProjectTwo).value,
          (packageBin in subProjectThree).value)
   moduleJars map { jar =>
     jar -> s"module/${jar.getName}"
   }
}

This will insure that the tgz/txz/zip can be generated. You can then either use the "generic" universal -> msi and universal -> rpm/deb mappings or create that mapping by hand if you desire.

Hope that helps!