我使用的是xsbt-proguard-plugin,這是一款與Proguard一起使用的SBT插件。如何使用xsbt-proguard-plugin排除/包含特定的軟件包?
我試圖想出一個Hive Deserializer一個Proguard的配置我寫的,它具有以下依存關係:
// project/Dependencies.scala
val hadoop = "org.apache.hadoop" % "hadoop-core" % V.hadoop
val hive = "org.apache.hive" % "hive-common" % V.hive
val serde = "org.apache.hive" % "hive-serde" % V.hive
val httpClient = "org.apache.httpcomponents" % "httpclient" % V.http
val logging = "commons-logging" % "commons-logging" % V.logging
val specs2 = "org.specs2" %% "specs2" % V.specs2 % "test"
加上非託管依賴:
// lib/UserAgentUtils-1.6.jar
因爲大多數這些都是爲本地單元測試或在Hadoop/Hive環境中提供,無論如何,我希望我的縮小jarfile只包括:
- Java類SnowPlowEventDeserializer.class和SnowPlowEventStruct.class
org.apache.httpcomponents.httpclient
commons-logging
lib/UserAgentUtils-1.6.jar
但我真的努力讓語法正確。我應該從我想保留的類的白名單開始,還是明確地過濾掉Hadoop/Hive/Serde/Specs2庫?我知道this SO question,但似乎並不適用於此。
如果我最初嘗試的白名單方式:
// Should be equivalent to sbt> package
import ProguardPlugin._
lazy val proguard = proguardSettings ++ Seq(
proguardLibraryJars := Nil,
proguardOptions := Seq(
"-keepattributes *Annotation*,EnclosingMethod",
"-dontskipnonpubliclibraryclassmembers",
"-dontoptimize",
"-dontshrink",
"-keep class com.snowplowanalytics.snowplow.hadoop.hive.SnowPlowEventDeserializer",
"-keep class com.snowplowanalytics.snowplow.hadoop.hive.SnowPlowEventStruct"
)
)
然後我得到一個Hadoop的處理錯誤,這麼清楚Proguard的仍試圖捆綁Hadoop的:
proguard: java.lang.IllegalArgumentException: Can't find common super class of [[Lorg/apache/hadoop/fs/FileStatus;] and [[Lorg/apache/hadoop/fs/s3/Block;]
同時,如果我嘗試Proguard's filtering syntax到建立我不想包括的圖書館黑名單:
import ProguardPlugin._
lazy val proguard = proguardSettings ++ Seq(
proguardLibraryJars := Nil,
proguardOptions := Seq(
"-keepattributes *Annotation*,EnclosingMethod",
"-dontskipnonpubliclibraryclassmembers",
"-dontoptimize",
"-dontshrink",
"-injars !*hadoop*.jar"
)
)
然後這似乎並不工作:
proguard: java.io.IOException: Can't read [/home/dev/snowplow-log-deserializers/!*hadoop*.jar] (No such file or directory)
任何幫助非常感謝!
由於埃裏克,我感謝幫助。最後,我無法超越重複的類錯誤,更不用說排除特定的jar。當我在SBT中有一個簡單的依賴關係列表時,排除特定的瓶子似乎有點笨拙,我寧願使用/註釋來包含/排除。最後,我採用了sbt-assembly的方法,見下文。 –