某些场景下,希望发布的包是已经混淆过的,防止repo中出现未混淆jar包,同时,也方便后续开发依赖测试最实际的效果,即直接使用已混淆的包作为依赖。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<!--混淆编译--> <plugin> <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> <attachArtifactClassifier></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.mcrmb</option> <option>-keep class **.package-info</option> <option>-keepattributes SourceFile,LineNumberTable,*Annotation*</option> <option>-keep class com.xxx.xxx { *;}</option> <!--option>-outjars out.jar</option--> </options> <outjar>../pg/</outjar> <libs> <lib>${java.home}/lib/rt.jar</lib> </libs> </configuration> </plugin> <!--发布(install)混淆后的版本--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.4</version> <executions> <execution> <phase>install</phase> <goals> <goal>install-file</goal> </goals> <configuration> <groupId>com.xxx</groupId> <artifactId>XXXX</artifactId> <version>${version}</version> <packaging>jar</packaging> <file>pg/${artifactId}-${version}.jar</file> </configuration> </execution> </executions> </plugin> |