如何在使用proguard-maven-plugin后组装项目

时间:2016-03-22 09:15:01

标签: java maven proguard maven-assembly-plugin

我正在尝试在打包我的应用时添加模糊处理步骤。我认为我必须在编译器插件和程序集之间插入Proguard插件(程序集只将我的所有应用程序和依赖项放入一个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而不是混淆的jar。

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

    <?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插件的配置。如果你看到一些奇怪的东西,请说出来。

感谢您的时间。

0 个答案:

没有答案