我整天都在尝试混淆我们正在开发的 Web 应用程序(我们将允许大客户将其托管在他们的服务器上),并且在浏览、搜索和尝试了很多之后,我无法减少收到的错误数量: “有 7283 个未解析的类或接口引用”
我从 20K 开始,所以我设法得到了一些改进......
这是我正在使用的 pom 配置:
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>4.8</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<configuration>
<obfuscate>true</obfuscate>
<includeDependency>true</includeDependency>
<options>
<option>-target 1.6</option>
<option>-allowaccessmodification</option>
<option><![CDATA[
-keep public class * {
public <init>(...);
public void set*(...);
public void init*(...);
public void close*(...);
public ** get*(...);
public boolean is*(...);
public boolean can*(...);
}
]]></option>
<option><![CDATA[
-keepclassmembers class * {
@javax.inject.Inject *;
@javax.inject.Named *;
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Qualifier *;
@org.springframework.beans.factory.annotation.Value *;
@org.springframework.beans.factory.annotation.Required *;
}
]]></option>
<option>-keep @org.springframework.stereotype.Service class *</option>
<option>-keep @org.springframework.stereotype.Controller class * </option>
<option>-keep @org.springframework.stereotype.Component class * </option>
<option>-keep @org.springframework.stereotype.Repository class *</option>
</options>
<inFilter>com/proton/**,!com/proton/protocol/**</inFilter>
<injar>${build.warname}.${project.packaging}</injar>
<outjar>${build.warname}-proguarded.${project.packaging}</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<addMavenDescriptor>false</addMavenDescriptor>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
</libs>
<proguardVersion>4.8</proguardVersion>
</configuration>
</plugin>
结果日志的很大一部分: https ://raw.github.com/gist/3708235/37b4cada40fa4742fd1e3ef0f24efd69fa232b28/Proguard
似乎至少有很大一部分错误来自 Spring 库,我确信我必须大量使用 keep 规则来修复一些动态调用,但如果有人可以帮助解决所有这些错误,我会很棒。