Maven集成Proguard

直接上代码

<plugin>
	<artifactId>maven-assembly-plugin</artifactId>
	<configuration>
		<archive>
			<manifest>
				<mainClass>xxx.Start</mainClass>
			</manifest>
		</archive>
		<descriptorRefs>
			<descriptorRef>jar-with-dependencies</descriptorRef>
		</descriptorRefs>
	</configuration>
	<executions>
		<execution>
			<!-- this is used for inheritance merges -->
			<id>make-assembly</id> 
			 <!-- Specify to perform the jar package merge 
			 operation on the package node. -->
			<phase>package</phase>
			<goals>
				<goal>single</goal>
			</goals>
		</execution>
	</executions>
</plugin>
<plugin><!--Confused code with obfuscated plugins -->
	<groupId>com.github.wvengen</groupId>
	<artifactId>proguard-maven-plugin</artifactId>
	<version>2.0.11</version>
	<executions>
		<execution>
			<phase>package</phase>
			<goals>
				<goal>proguard</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<attach>true</attach>
		<attachArtifactClassifier>pg</attachArtifactClassifier>
		<proguardInclude>${basedir}/src/main/resources/confs/proguard.conf</proguardInclude>
		<!--Specify the confusing jar package, I am here to confuse the jar 
			package output in the previous step. -->
		<injar>spa-posbridge-simphony-pat-0.0.1-SNAPSHOT-jar-with-dependencies.jar</injar>
		<!--Specify the output of the jar -->
		<outjar>${project.build.finalName}-pg</outjar>
		<obfuscate>true</obfuscate>
		<!-- add dependency jar for exception -->
		<libs>
			<lib>${java.home}/lib/rt.jar</lib>
			<lib>${java.home}/lib/jce.jar</lib>
			<!-- <lib>D:/workspace3/datacube/lib/apache-axiom-api-1.2.7.jar</lib> -->
			<!-- <lib>D:/workspace3/datacube/lib/axis2-kernel-1.7.1.jar</lib> -->
		</libs>
	</configuration>
</plugin>

比较麻烦的是第三方的jar必须手动一个一个忽略.
配置文件proguard.conf:


-ignorewarnings
#donot shrink
-dontshrink    
#donot optimize 
-dontoptimize 
-dontskipnonpubliclibraryclasses 
-dontskipnonpubliclibraryclassmembers 
-dontnote 
-keepattributes Signature
#Keep the source name and line number (there is a clear stack information 
#when the exception occurs), annotate (by default, all annotations will be 
#filtered out, which will affect the annotation of the framework) 
-keepattributes
	Exceptions,InnerClasses,*Annotation*,Signature,LineNumberTable
-keep class
	com.xxx.Start
-keepclassmembers class
	com.xxx.Start{ *;}
# Keep the bean class name and attribute name unchanged
-keep class
	xxx.dto.**
-keepclassmembers class
	xxx.dto.** { *;}
-keepclasseswithmembers class * { 
    public <init>(xxx); 
} 
-keep class org.apache.commons.logging.** { *; }
-dontwarn org.apache.commons.logging.**
-keep class javax.annotation.** { *; }
-dontwarn javax.annotation.**
-keep xxx.dto.**
-keep interface * extends * { *; }

#The following configuration of third-party packages does not participate in confusion

-keepclassmembers class ch.qos.logback.** { *;}
-dontwarn ch.qos.logback.**
-keep class ch.qos.logback.**

-keepclassmembers class com.alibaba.** { *;}
-dontwarn com.alibaba.**
-keep class com.alibaba.**

-keepclassmembers class io.netty.** { *;}
-dontwarn io.netty.**
-keep class io.netty.**


-keepclassmembers class javax.ws.** { *;}
-dontwarn javax.ws.**
-keep class javax.ws.**

-keepclassmembers class com.sun.** { *;}
-dontwarn com.sun.**
-keep class com.sun.**

-keepclassmembers class sun.** { *;}
-dontwarn sun.**
-keep class sun.**

-keepclassmembers class javax.** { *;}
-dontwarn javax.**
-keep class javax.**

-keepclassmembers class retrofit2.** { *;}
-dontwarn retrofit2.**
-keep class retrofit2.**

-keepclassmembers class com.google.** { *;}
-dontwarn com.google.**
-keep class com.google.**

-keepclassmembers class okhttp3.** { *;}
-dontwarn okhttp3.**
-keep class okhttp3.**

-keepclassmembers class springfox.** { *;}
-dontwarn springfox.**
-keep class springfox.**

-keepclassmembers class com.fasterxml.** { *;}
-dontwarn com.fasterxml.**
-keep class com.fasterxml.**

-keepclassmembers class org.** { *;}
-dontwarn org.**
-keep class org.**


-keepclassmembers class net.** { *;}
-dontwarn net.**
-keep class net.**

需要注意的是如果在程序中有用到 getResource() 方法,一定要将使用方法的类加入如下配置,因为混淆后此方法位的到的值为null.
-keepdirectories foo.MyClass
-keeppackagenames foo.MyClass

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值