0

使用 Proguard 7.1.1 和 Gradle 7.2,我有这个任务:

task optimize(type: proguard.gradle.ProGuardTask) {
    injars  'build/libs/apex.war'
    outjars 'build/libs/apex_min.war'
    
    dontwarn 'module-info'
    ignorewarnings
    
    libraryjars "${System.getProperty('java.home')}/lib/"

    keepattributes '*Annotation*'
    keepattributes 'Signature'
    keepattributes 'InnerClasses'
    
    keep 'public class ____embedded.____EntryPoint { \
        public static void main(java.lang.String[]); \
    }'
    
    keep 'public class ____bootstrap.____Bootstrap'
    
    // Preserve all public servlets.
    keep 'public class * implements javax.servlet.Servlet'

    // Preserve all native method names and the names of their classes.
    keepclasseswithmembernames includedescriptorclasses: true, 'class * { \
        native <methods>; \
    }'

    // Preserve the special static methods that are required in all enumeration
    // classes.
    keepclassmembers allowoptimization: true, 'enum * { \
        public static **[] values(); \
        public static ** valueOf(java.lang.String); \
    }'

    // Explicitly preserve all serialization members. The Serializable interface
    // is only a marker interface, so it wouldn't save them.
    // You can comment this out if your library doesn't use serialization.
    // If your code contains serializable classes that have to be backward
    // compatible, please refer to the manual.
    keepclassmembers 'class * implements java.io.Serializable { \
        static final long serialVersionUID; \
        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(); \
    }'
}

我告诉它要保留课程____Bootstrap,但它会删除它,请参见下面带有源代码并在底角.war生成的图像:.war

在此处输入图像描述

Proguard 完全删除了整个classes目录。

4

0 回答 0