我有一个结构如下的项目:
--resources
--src
|
|-- mypackage.main
|
|-- MainClassOne.scala
|-- MainClassTwo.scala
|-- mypackage.utils
|
|-- SomeOne.scala
|-- SomeTwo.scala
我正在尝试制造两个胖子罐,每个胖子都有自己的Main类。用jarOne.jar
说MainClassOne
,用jarTwo.jar
说MainClassTwo
下面是我的sbt文件的内容:
lazy val assemblySettings = Seq(
assemblyMergeStrategy in assembly := {
case "application.conf" => MergeStrategy.concat
case "defaults.conf" => MergeStrategy.concat
case PathList("UnusedStubClass.class") => MergeStrategy.discard
case x => val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
)
lazy val BuildOne = (project in file("."))
.settings(mainClass in Compile := Some("mypackage.main.MainClassOne"))
.settings(mainClass in assembly := Some("mypackage.main.MainClassOne"))
.settings(assemblyJarName in assembly := "jarOne.jar")
.settings(myMetaSettings: _*)
.settings(myScalaSettings: _*)
.settings(resolvers ++= myRepositories)
.settings(libraryDependencies ++= myDependencies)
.enablePlugins(AssemblyPlugin)
.settings(assemblySettings: _*)
lazy val BuildTwo = (project in file("."))
.settings(mainClass in Compile := Some("mypackage.main.MainClassTwo"))
.settings(mainClass in assembly := Some("mypackage.main.MainClassTwo"))
.settings(assemblyJarName in assembly := "jarTwo.jar")
.settings(myMetaSettings: _*)
.settings(myScalaSettings: _*)
.settings(resolvers ++= myRepositories)
.settings(libraryDependencies ++= myDependencies)
.enablePlugins(AssemblyPlugin)
.settings(assemblySettings: _*)
但是,我注意到这只会产生一个jar-jarTwo.jar
-而不是我最初希望的两个。
这个想法是要能够从同一项目构建jar(具有不同的名称和主类)。赞赏有关如何使用sbt实现此目标的意见。
答案 0 :(得分:0)
这只是一个随机的想法,所以我可能是错的,但是您可以尝试
val AlternativeAssembly: Configuration = config("alt") extend Assembly describedAs "Alternative assembly config"
...
project
.settings(Assembly / mainClass := Some("package.Main1"))
.settings(AlternativeAssembly / mainClass := Some("package.Main2"))
您将运行的
project/assembly
project/alt:assembly