0

我正在努力让 sbt-proguard 插件工作。我有一个想要混淆的类库,但如果没有上述错误,我似乎无法让插件输出。我已经指定了保留选项,或者至少我认为我有,但我没有运气。我从 Proguard 网站上复制了 keep 选项,上面说它是用于类库的。此外,我认为插件不会响应我配置的选项。

例如,我想要更详细的输出,看看输出是否可以给我一个关于我做错了什么的线索。但是,每当我查看日志文件时,它总是指定默认选项。下面是我的配置。有人可以帮我解决这个问题吗?我完全迷路了。谢谢

import sbt.Keys._
import com.typesafe.sbt.SbtProguard._

import ProguardKeys._


lazy val commonDependencies = Seq(
  Dependencies.Libraries.junit,
  Dependencies.Libraries.springBootLogging,
  Dependencies.Libraries.scalaMock,
  Dependencies.Libraries.joda,
  Dependencies.Libraries.scalaTestPlus,
  Dependencies.Libraries.scalaXml,
  Dependencies.Libraries.commonsCodec,
  Dependencies.Libraries.typeSafeConfig
)

val keepClasses =
  """
    |-injars       in.jar
    |-outjars      out.jar
    |-libraryjars  <java.home>/lib/rt.jar
    |-printmapping out.map
    |
    |-keepparameternames
    |-renamesourcefileattribute SourceFile
    |-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
    |                SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
    |
    |-keep public class * {
    |    public protected *;
    |}
    |
    |-keepclassmembernames class * {
    |    java.lang.Class class$(java.lang.String);
    |    java.lang.Class class$(java.lang.String, boolean);
    |}
    |
    |-keepclasseswithmembernames,includedescriptorclasses class * {
    |    native <methods>;
    |}
    |
    |-keepclassmembers,allowoptimization enum * {
    |    public static **[] values();
    |    public static ** valueOf(java.lang.String);
    |}
    |
    |-keepclassmembers class * implements java.io.Serializable {
    |    static final long serialVersionUID;
    |    private static final java.io.ObjectStreamField[] serialPersistentFields;
    |    private void writeObject(java.io.ObjectOutputStream);
    |    private void readObject(java.io.ObjectInputStream);
    |    java.lang.Object writeReplace();
    |    java.lang.Object readResolve();
    |}
  """.stripMargin

proguardSettings

lazy val skedaddleCore = (project in file(".")).
  settings(BuildSettings.buildSettings: _*).
  settings(
    name := "core",
    resolvers := Resolvers.all,
    libraryDependencies ++= commonDependencies,
    merge in Proguard := true,
    proguardVersion in Proguard := "5.2.1",
    options in Proguard --= Seq("-dontnote", "-dontwarn", "-ignorewarnings"),
    options in Proguard ++= Seq("-verbose", "-dontshrink"),
    options in Proguard += keepClasses
  )
4

1 回答 1

0

我终于用下面的配置让插件做我想做的事。

import sbt.Keys._
import com.typesafe.sbt.SbtProguard._

lazy val commonDependencies = Seq(
  Dependencies.Libraries.junit,
  Dependencies.Libraries.springBootLogging,
  Dependencies.Libraries.scalaMock,
  Dependencies.Libraries.joda,
  Dependencies.Libraries.scalaTestPlus,
  Dependencies.Libraries.scalaXml,
  Dependencies.Libraries.commonsCodec,
  Dependencies.Libraries.typeSafeConfig
)

proguardSettings

ProguardKeys.proguardVersion in Proguard := "5.2.1"

ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings")

ProguardKeys.inputs in Proguard <<= (dependencyClasspath in Compile) map { _.files }

ProguardKeys.filteredInputs in Proguard <++= (packageBin in Compile) map ProguardOptions.noFilter

val keepClasses =
  """
    |-keepparameternames
    |-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
    |                SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
    |
    |-keep,includedescriptorclasses interface com.** {
    |    <methods>;
    |}
  """.stripMargin

ProguardKeys.options in Proguard += keepClasses

lazy val skedaddleCore = (project in file(".")).
  settings(BuildSettings.buildSettings: _*).
  settings(
    name := "core",
    resolvers := Resolvers.all,
    libraryDependencies ++= commonDependencies
  )
于 2016-08-05T02:53:08.777 回答