繁体   English   中英

ProGuard + Spring Boot + Maven插件

[英]ProGuard + Spring Boot + Maven Plugin

伙计们,我正在尝试使用proguard-maven-plugin混淆.jar应用程序。
当我尝试执行混淆过程时,出现错误消息,指出存在意外类。

我正在使用Spring Boot 1.4.1.RELEASE和Proguard Maven插件2.0.13。

这是我的proguard.conf

-injars /workspace/base/target/test-1.0.0.jar

-libraryjars /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/rt.jar

-dontshrink
-dontoptimize
-dontobfuscate
-dontusemixedcaseclassnames
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod

-adaptresourcefilenames **.properties
-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF

-dontpreverify
-verbose


-keepclasseswithmembers public class * {
    public static void main(java.lang.String[]);
}

-keepclassmembers enum  * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * extends java.beans.BeanInfo

-keep class * {
    void set*(***);
    void set*(int,***);
    boolean is*();
    boolean is*(int);
    *** get*();
    *** get*(int);
}

-assumenosideeffects public class java.lang.System {
    public static long currentTimeMillis();
    static java.lang.Class getCallerClass();
    public static int identityHashCode(java.lang.Object);
    public static java.lang.SecurityManager getSecurityManager();
    public static java.util.Properties getProperties();
    public static java.lang.String getProperty(java.lang.String);
    public static java.lang.String getenv(java.lang.String);
    public static java.lang.String mapLibraryName(java.lang.String);
    public static java.lang.String getProperty(java.lang.String,java.lang.String);
}

pom.xml文件。 我只是通过插件通知配置。

<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>2.0.13</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>proguard</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <obfuscate>false</obfuscate>
        <outFilter>**/BOOT-INF/classes/ **.class</outFilter>

        <proguardInclude>${basedir}/proguard.conf</proguardInclude>
        <outputDirectory>${project.build.directory}</outputDirectory>

        <injar>${project.build.finalName}.jar</injar>
        <outjar>${project.build.finalName}-min.jar</outjar>
    </configuration>
</plugin>

但是,在执行过程中,我得到了应用程序中所有类的以下返回信息。

Warning: class [BOOT-INF/classes/br/com/base/BaseApplication.class] unexpectedly contains class [br.com.base.BaseApplication]
Warning: class [BOOT-INF/classes/br/com/base/controller/CaixaController.class] unexpectedly contains class [br.com.base.controller.CaixaController]
[...]

以及ProGuard的最终输出。 PS: 所有类都在BOOT-INF/classes目录中

Warning: there were 97 classes in incorrectly named files.
You should make sure all file names correspond to their class names.
The directory hierarchies must correspond to the package hierarchies.
     (http://proguard.sourceforge.net/manual/troubleshooting.html#unexpectedclass)
If you don't mind the mentioned classes not being written out,
you could try your luck using the '-ignorewarnings' option.
Please correct the above warnings first.

谁能想象我可以尝试的替代方法? 谢谢。

为了解决这个问题,我确保更改pom中插件的顺序。 Proguard插件应该放在第一位,然后是spring boot插件。

此外,请确保您在Spring Boot配置中指定了<goal>repackage</goal> 使用正确的顺序和指定的重新包装目标,将进行proguard混淆/优化/无论您配置了什么,然后生成一个jar。 然后,Spring Boot插件会将该jar重新打包为可执行文件,并且一切正常。

我的插件配置来自pom.xml:

<project ...>
....
<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>proguard</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <proguardInclude>${basedir}/proguard.conf</proguardInclude>
        <libs>
            <lib>${java.home}/lib/rt.jar</lib>
            <lib>${java.home}/lib/jce.jar</lib>
        </libs>
    </configuration>
</plugin>
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
            <configuration>
                <start-class>org.springframework.boot.loader.JarLauncher</start-class>
            </configuration>
        </execution>
    </executions>
</plugin>
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM