proguard for multiple maven module project

自作多情 提交于 2019-12-24 05:05:05

问题


I have a plugin reference to proguard in a multi-module maven project.

The functionality of my project is fully tested and works...until I add proguard.

Structure of my Project

parent-pom  
  -module-a-pom  
  -module-b-pom

tester-pom
  1. module-b has a dependency on module-a.
  2. module-a and module-b are both installed to my local maven repository.
  3. tester has dependencies on both module-a and module-b.
  4. My proguard.conf file is next to the parent-pom pom.xml file on the file system.
  5. I configure proguard in both module-a and module-b pom.xml files.

My proguard config looks like so:

<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>2.0.8</version>
    <executions>
        <execution>
            <id>process-classes-with-proguard</id>
            <phase>process-classes</phase>
            <goals>
                <goal>proguard</goal>
            </goals>
            <configuration>
                <injar>classes</injar>
                <proguardVersion>5.1</proguardVersion>
                <proguardInclude>${project.basedir}/../proguard.conf</proguardInclude>
                <libs>
                    <lib>${java.bootstrap.classes}</lib>
                    <lib>${java.secure.socket.extension.classes}</lib>
                    <lib>${java.cryptographic.extension.classes}</lib>
                </libs>
                <obfuscate>true</obfuscate>
            </configuration>
          </execution>
       </executions>
       <dependencies>
          <dependency>
              <groupId>net.sf.proguard</groupId>
              <artifactId>proguard-base</artifactId>
              <version>5.1</version>
              <scope>runtime</scope>
          </dependency>
       </dependencies>
</plugin>

I have the added complexity that my project is using GSON to deserialise some incoming JSON from an external component I have no control over.

Executing proguard as part of the build causes the GSON code to throw NullPointerExceptions

The code that is effected by proguard is:

Gson gson = new Gson();
Type collectionType = new TypeToken<ArrayList<MyType>>(){}.getType();
ArrayList<MyType> myTypes = gson.fromJson(json, collectionType);

If proguard is commented out in my pom files (so it doesn't execute), this code (and the rest of my project) works like a charm.

How can I configure proguard to obsfuscate my code but not break the functionality? Is this possible with a multimodule project?

Does anyone out there know how to configure proguard for a multimodule maven project?

NB: I have already tried this and it seemed to make no difference to the outcome.


回答1:


I eventually got this working by:

  1. Using the Windows Proguard application and selecting relatively basic settings through the wizard
  2. Exporting the configuration
  3. Closing my eyes and pressing the go button.

..and it worked!



来源:https://stackoverflow.com/questions/27665179/proguard-for-multiple-maven-module-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!