spring boot与proguard 结合,混淆代码

maven配置

<build>
        <finalName>${artifactId}finalName>
        <plugins>
            <plugin>
                <groupId>com.github.wvengengroupId>
                <artifactId>proguard-maven-pluginartifactId>
                <executions>
                    <execution>
                        <phase>packagephase>
                        <goals><goal>proguardgoal>goals>
                    execution>
                executions>
                <configuration>
                    <proguardVersion>5.3.3proguardVersion>
                    <injar>${project.build.finalName}.jarinjar>
                    <outjar>${project.build.finalName}.jaroutjar>
                    <obfuscate>trueobfuscate>

                    <options>
                        <option>-dontshrinkoption>
                        <option>-dontoptimizeoption>
                        <option>-adaptclassstringsoption>
                        <option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
                            SourceFile,LineNumberTable,*Annotation*,EnclosingMethodoption>
                        <option>-keepnames interface **option>
                        <option>-keepparameternamesoption>

                        <option>-keep class !com.adups.iot.web.** { *; }option>
                        <option>-keep class com.adups.iot.web.Application { *; }option>
                        <option>-keep class com.adups.iot.web.bean.** { *; }option>
                        <option>-keep class com.adups.iot.web.common.JsonResult{*; }option>
                        <option>-keep class com.adups.iot.web.conf.** { *; }option>

                        <option>-keepclassmembers class com.adups.iot.web.security.MyShiro { *; }option>
                        <option>-keep class com.adups.iot.web.util.ShiroUtil { *; }option>

                        <option>-keep interface * extends * {*;}option>

                        <option>-keep @org.springframework.stereotype.Service class *option>
                        <option>-keep @org.springframework.stereotype.Controller class * {*;}option>
                        <option>-keepclassmembers class * {
                            @org.springframework.beans.factory.annotation.Autowired *;
                            @org.springframework.beans.factory.annotation.Value *;
                            }
                        option>
                    options>
                    <libs>
                        
                        <lib>${java.home}/lib/rt.jarlib>
                        
                        <lib>${java.home}/lib/jce.jarlib>
                    libs>
                configuration>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.proguardgroupId>
                        <artifactId>proguard-baseartifactId>
                        <version>5.3.3version>
                        <scope>runtimescope>
                    dependency>
                dependencies>
            plugin>

            
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackagegoal>
                        goals>
                        <configuration>
                            <mainClass>com.adups.iot.web.ApplicationmainClass>
                        configuration>
                    execution>
                executions>
            plugin>
        plugins>
    build>

建议方法:

一般先除了项目的下包,其他全部混淆
-keep class !com.adups.iot.web.* { ; }
com.adups.iot.web是我的项目package name.
-keep class com.adups.iot.web.bean.* { ; }
-keep class com.adups.iot.web.common.* { ; }
先将每个子包加入,再逐步取消.
是每一个子包.

spring boot与proguard 结合,混淆代码_第1张图片

注意:
如果找到混淆后类报错,怎么找原来的类?
spring boot与proguard 结合,混淆代码_第2张图片

从proguard_map.txt在找到映射前的类.
再取消这个类这个类或该类的方法的混淆.

你可能感兴趣的:(SpringBoot)