How to assembly a project after using proguard-maven-plugin

前端 未结 1 637
有刺的猬
有刺的猬 2020-12-21 04:33

I am trying to add an obfuscation step while packaging my app. I supposed that I had to insert the Proguard plugin between the compiler plugin and the assembly (the assembly

相关标签:
1条回答
  • 2020-12-21 05:15

    I solved it by abandoning maven assembly plugin to shade plugin. Hope it might help someone.

                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>3.2</version>
                                <configuration>
                                    <source>1.7</source>
                                    <target>1.7</target>
                                </configuration>
                        </plugin>
    
                        <!--Obfuscation-->
                        <plugin>
                            <groupId>com.github.wvengen</groupId>
                            <artifactId>proguard-maven-plugin</artifactId>
                            <version>2.0.13</version>
                            <executions>
                                <execution>
                                    <id>obfuscation-packaging</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>proguard</goal>
                                    </goals>
                                    <configuration>
                                        <proguardVersion>5.2</proguardVersion>
                                        <obfuscate>true</obfuscate>
                                        <addMavenDescriptor>true</addMavenDescriptor>
                                        <injar>${project.build.finalName}.jar</injar>
                                        <outjar>${project.build.finalName}.jar</outjar>
                                        <mappingFileName>proguard_map.txt</mappingFileName>
                                        <seedFileName>proguard_seed.txt</seedFileName>
                                        <libs>
                                            <lib>${java.home}/lib/rt.jar</lib>
                                        </libs>
    
                                        <options>
                                        ...
                                        </options>
                                    </configuration>
                                </execution>
                            </executions>
                            <dependencies>
                                <dependency>
                                    <groupId>net.sf.proguard</groupId>
                                    <artifactId>proguard-base</artifactId>
                                    <version>5.2</version>
                                </dependency>
                            </dependencies>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-shade-plugin</artifactId>
                            <version>2.4.3</version>
                            <executions>
                              <execution>
                                <phase>package</phase>
                                <goals>
                                  <goal>shade</goal>
                                </goals>
                                <configuration>
                                    <transformers>
                                      <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>xxx.Main</mainClass>
                                      </transformer>
                                    </transformers>
                                    <filters>
                                        <filter>
                                            <artifact>*:*</artifact>
                                            <excludes>
                                                <exclude>META-INF/*.SF</exclude>
                                                <exclude>META-INF/*.DSA</exclude>
                                                <exclude>META-INF/*.RSA</exclude>
                                            </excludes>
                                        </filter>
                                    </filters>
                                </configuration>
                              </execution>
                            </executions>
                        </plugin>
    
    0 讨论(0)
提交回复
热议问题