1.proguard-maven-plugin
<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>
<attach>true</attach>
<attachArtifactClassifier>pg</attachArtifactClassifier>
<!-- attach 的作用是在 install 与 deploy 时将生成的 pg 文件也安装与部署 -->
<options> <!-- 详细配置方式参考 ProGuard 官方文档 -->
<!--<option>-dontobfuscate</option>-->
<option>-ignorewarnings</option> <!--忽略所有告警-->
<option>-dontshrink</option> <!--不做 shrink -->
<option>-dontoptimize</option> <!--不做 optimize -->
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
<option>-repackageclasses com.lwf.proguard.example.project2.pg</option>
<!--平行包结构(重构包层次),所有混淆的类放在 pg 包下-->
<!-- 以下为 Keep,哪些内容保持不变,因为有一些内容混淆后(a,b,c)导致反射或按类名字符串相关的操作失效 -->
<option>-keep class **.package-info</option>
<option>-keep class **.TestClass { *;}</option>
<!--保持包注解类-->
<option>-keepattributes Signature</option>
<!--JAXB NEED,具体原因不明,不加会导致 JAXB 出异常,如果不使用 JAXB 根据需要修改-->
<!-- Jaxb requires generics to be available to perform xml parsing and without this option ProGuard was not retaining that information after obfuscation. That was causing the exception above. -->
<option>-keepattributes SourceFile,LineNumberTable,*Annotation*</option>
<!--保持源码名与行号(异常时有明确的栈信息),注解(默认会过滤掉所有注解,会影响框架的注解)-->
<option>-keepclassmembers enum com.lwf.proguard.example.project2.** { *;}</option>
<!--保持枚举中的名子,确保枚举 valueOf 可以使用-->
<option>-keep class com.lwf.proguard.example.project2.bean.** { *;}</option>
<!--保持 Bean 类,(由于很多框架会对 Bean 中的内容做反射处理,请根据自己的业务调整) -->
<option>-keep class com.lwf.proguard.example.project2.Project2 { public void init(); public void
destroy(); }
</option>
<!-- 保持对外的接口性质类对外的类名与方法名不变 -->
</options>
<outjar>${project.build.finalName}-pg</outjar>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
</libs>
</configuration>
</plugin>
-
maven-shade-plugin
3.maven-Assembly-plugin
<!-- 方法三:使用 maven-Assembly-plugin插件打可执行包-->
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.lwf.test.TestClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
-->
4.onejar-maven-plugin
<!-- 方法四:使用 onejar-maven-plugin插件打可执行包-->
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.lwf.test.TestClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<attachToBuild>true</attachToBuild>
<classifier>onejar</classifier>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
-->
5.mvaen-jar-plugin和 maven-dependency-plugin
<!-- 方法五:使用maven-jar-plugin和maven-dependency-plugin打可执行包,引用的包放包外面文件夹下 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/log4j.properties</exclude>
</excludes>
<archive>
<!-- 包里面是否包含pom.xml文件和pom.properties文件 -->
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.lwf.test.TestClass</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- exclude junit, we need runtime dependency only -->
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<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>
<attach>true</attach>
<attachArtifactClassifier>pg</attachArtifactClassifier>
<!-- attach 的作用是在 install 与 deploy 时将生成的 pg 文件也安装与部署 -->
<options> <!-- 详细配置方式参考 ProGuard 官方文档 -->
<!--<option>-dontobfuscate</option>-->
<option>-ignorewarnings</option> <!--忽略所有告警-->
<option>-dontshrink</option> <!--不做 shrink -->
<option>-dontoptimize</option> <!--不做 optimize -->
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
<option>-repackageclasses com.lwf.proguard.example.project2.pg</option>
<!--平行包结构(重构包层次),所有混淆的类放在 pg 包下-->
<!-- 以下为 Keep,哪些内容保持不变,因为有一些内容混淆后(a,b,c)导致反射或按类名字符串相关的操作失效 -->
<option>-keep class **.package-info</option>
<option>-keep class **.TestClass { *;}</option>
<!--保持包注解类-->
<option>-keepattributes Signature</option>
<!--JAXB NEED,具体原因不明,不加会导致 JAXB 出异常,如果不使用 JAXB 根据需要修改-->
<!-- Jaxb requires generics to be available to perform xml parsing and without this option ProGuard was not retaining that information after obfuscation. That was causing the exception above. -->
<option>-keepattributes SourceFile,LineNumberTable,*Annotation*</option>
<!--保持源码名与行号(异常时有明确的栈信息),注解(默认会过滤掉所有注解,会影响框架的注解)-->
<option>-keepclassmembers enum com.lwf.proguard.example.project2.** { *;}</option>
<!--保持枚举中的名子,确保枚举 valueOf 可以使用-->
<option>-keep class com.lwf.proguard.example.project2.bean.** { *;}</option>
<!--保持 Bean 类,(由于很多框架会对 Bean 中的内容做反射处理,请根据自己的业务调整) -->
<option>-keep class com.lwf.proguard.example.project2.Project2 { public void init(); public void
destroy(); }
</option>
<!-- 保持对外的接口性质类对外的类名与方法名不变 -->
</options>
<outjar>${project.build.finalName}-pg</outjar>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
</libs>
</configuration>
</plugin>
</plugins>
</build>
</project>