我对scala和sbt世界非常陌生,我试图用sbt管理我的所有新项目,而不是使用maven。但现在我处在一个我不知道的地步,因为我无法找到mavnen-shade插件的任何对应物。我发现只有插件包含所有依赖项,但这不是我需要的。那么有人知道一个插件将某些依赖项包含在jar中吗?
答案 0 :(得分:0)
我使用sbt-proguard插件在Proguard上取得了成功。我花了一段时间来设置它,我不得不关闭一些Proguard功能才能使它工作,但最终我得到了我想要的东西:我可以执行的单个jar" java - jar",甚至在没有安装scala的系统上。
以下是启用插件的project/plugins.sbt
:
resolvers += Resolver.url("sbt-plugin-releases-scalasbt", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2")
以下是我的build.sbt中的一些片段来配置它:
scalaVersion := "2.10.2"
proguardSettings
ProguardKeys.options in Proguard += ProguardOptions.keepMain("io.package.my.app.Main")
ProguardKeys.options in Proguard ++= Seq(
"-keep class com.sun.xml.wss.impl.misc.XWSSProcessorFactory2_0Impl { *; }", // created dynamically by XWSSProcessorFactory
//
"-dontshrink",
"-dontobfuscate",
"-dontoptimize",
//
// Don't warn is necessary to avoid ProGuard refusing to build the jar.
//
"-dontwarn com.sun.**",
"-dontwarn org.apache.**",
"-dontwarn scala.**",
//
// Don't note just reduces clutter in the build output. If you make changes
// to the ProGuard configuration, you might want to remove these temporarily to
// help debug the new configuration until it's working correctly.
//
"-dontnote com.sun.**",
"-dontnote org.apache.**",
"-dontnote scala.**"
)
//"-printconfiguration /tmp/proguard"
// Examples of how to filter classes.
ProguardKeys.inputFilter in Proguard := { file =>
file.name match {
case "classes" => None
case "org.apache.karaf.shell.console-2.3.2.jar" => Some("org/apache/karaf/shell/**,org/apache/felix/gogo/commands/**")
case "jline-2.9.jar" => Some("jline/**")
case "org.apache.karaf.jaas.modules-2.3.2.jar" => Some("org/apache/karaf/jaas/modules/**")
case "org.apache.karaf.jaas.config-2.3.2.jar" => Some("org/apache/karaf/jaas/config/**")
case "org.osgi.compendium-4.3.1.jar" => Some("!**")
case _ => Some("!META-INF/**")
}
}
答案 1 :(得分:-1)
我正在寻找类似的事情,因为我完全厌倦了跨版本的后缀错误,并从sbt-assembly重复删除错误。
我设法找到" onejar"插件但它已经整整一年没有更新,请告诉我是否有效:https://github.com/sbt/sbt-onejar