使用sbt-osgi插件,可以通过使用OsgiKeys.embeddedJars属性来创建“胖jars”。
例如,以下代码(摘自此test)将名称以jUnit开头的每个依赖项嵌入到编译后的jar中:
OsgiKeys.embeddedJars := (Keys.externalDependencyClasspath in Compile).value map (_.data) filter (
_.getName startsWith "junit")在我的例子中,我的依赖项声明如下:
libraryDependencies += "org.apache.logging.log4j" % "log4j-api" % "2.7" % Provided
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % akkaVersion我希望每个库都嵌入到fat jar中,除了那些用Provided注释的库。因此,在这种情况下,com.typesafe.akka应该包含在fat jar中,而org.apache.logging.log4j不应该编译到jar中。
有没有办法修改上面的filter方法,让它满足我的需求?
发布于 2019-03-11 21:04:48
我找到了一种方法来实现我想要的:
OsgiKeys.embeddedJars := (Keys.externalDependencyClasspath in Compile).value.map(_.data).filter(
file => {
/*
* Find configs for file and return false if it includes "test" or "provided"
*/
libraryDependencies.value.map(x => { (x.name.toLowerCase, x.configurations.map(_.toLowerCase)) })
.find { case (n, _) => file.getName.toLowerCase.contains(n) }
.flatMap {case (_, c) => c} match {
case x if x.contains("test") => false
case x if x.contains("provided") => false
case _ => true
}
})https://stackoverflow.com/questions/55096915
复制相似问题