如何在使用proguard-maven-plugin后组装项目 [英] How to assembly a project after using proguard-maven-plugin

查看:396
本文介绍了如何在使用proguard-maven-plugin后组装项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在打包我的应用时添加模糊处理步骤。我认为我必须在编译器插件和程序集之间插入Proguard插件(程序集只将我的所有应用程序和依赖项放入一个jar中)。

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 just put all of my app and dependencies into one single jar).

<build>
    <finalName>myApp</finalName>
    <plugins>
        <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>

        <plugin>
             <groupId>com.github.wvengen</groupId>
             <artifactId>proguard-maven-plugin</artifactId>
             <version>2.0.11</version>
             <executions>
                  <execution>
                  <id>obfuscation-packaging</id>
                  <phase>package</phase>
                  <goals>
                      <goal>proguard</goal>
                  </goals>
                  <configuration>
                      <proguardVersion>5.2</proguardVersion>
                      <obfuscate>true</obfuscate>
                      <attach>true</attach>
                      <appendClassifier>false</appendClassifier>
                      <addMavenDescriptor>true</addMavenDescriptor>
                      <injar>${project.build.finalName}.jar</injar>
                      <outjar>${project.build.finalName}.jar</outjar>
                      <injarNotExistsSkip>true</injarNotExistsSkip>
                      <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>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>create-executable-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>assembly.xml</descriptor>
                        </descriptors>
                        <archive>
                            <manifest>
                                <mainClass>myApp.Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

编译工作正常,混淆也是如此,但装配似乎是用普通的jar制作的,而不是混淆的。

The compiling works fine, so does the obfuscation, but the assembly seems to be made with the normal jar, not the obfuscated one.

如果需要,这是我的assembly.xml:

Here is my assembly.xml if needed:

    <?xml version="1.0" encoding="UTF-8"?>
    <assembly>
       <id>with-dep</id>
       <formats>
         <format>jar</format>
       </formats>
       <includeBaseDirectory>false</includeBaseDirectory>
       <dependencySets>
         <dependencySet>
           <!-- unpack les dépendances avant de les inclures dans le jar final de l'application -->
           <unpack>true</unpack>
           <scope>runtime</scope>
           <useProjectArtifact>false</useProjectArtifact>
         </dependencySet>
       </dependencySets>
       <fileSets>
         <fileSet>
           <directory>${project.build.outputDirectory}</directory>
           <outputDirectory></outputDirectory>
         </fileSet>
       </fileSets>
    </assembly>

最后,myApp.jar被混淆了,但myApp-with-dep.jar却没有。 ..
我也很准确,我不太确定我的proguard插件的配置。如果你看到一些奇怪的东西,请说出来。

In the end, myApp.jar is obfuscated, but myApp-with-dep.jar is not... I also precise that I'm not quite sure about the configuration of my proguard plugin. If you see something weird, say it.

感谢您的时间。

推荐答案

我通过放弃maven程序集插件来解决插件问题。希望它可以帮到某人。

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>

这篇关于如何在使用proguard-maven-plugin后组装项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆