简体   繁体   中英

Maven, Proguard and a jar I don't want

I'm obsfucating a project with the proguard-maven-plugin. Everything works fine except one thing: I don't want the original jar, neither in the target directory nor deployed in the repository. At the moment, I get the orignal jar and the obsfucated jar. Leaving it this way would cause problems within our buildserver as both artifacts would be deployed resulting in duplicate interfaces in the classpath. Using a blacklist on the buildserver is not an option.

Any idea?

Thank you!

You just need to specify the injar and outjar parameter pointed to the same jar, proguard will override the original jar.

My proguard setting (this setting for java 6, for java 7, change the groupid, artifactid and version accordingly):

<plugin>
    <groupId>com.pyx4me</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>2.0.4</version>
    <executions>
        <execution>
            <phase>process-classes</phase>
            <goals>
                <goal>proguard</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <obfuscate>true</obfuscate>
        <includeDependency>false</includeDependency>
        <injar>classes</injar>
        <maxMemory>512m</maxMemory>
        <libs>
            <!-- dependency jar here -->
        </libs>
        <options>
            <option>-keepattributes *Annotation*</option>
            <option>-allowaccessmodification</option>
            <option>-dontskipnonpubliclibraryclasses</option>
            <option>-dontskipnonpubliclibraryclassmembers</option>
            <option>-dontusemixedcaseclassnames</option>
            <option>-dontshrink </option>
        </options>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>net.sf.proguard</groupId>
            <artifactId>proguard</artifactId>
            <version>4.4</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>

HTH.

If anybody has this issue, following configuration has worked for me. This renames the original jar to {final name}_proguard_base.jar and overrides the project jar with processed jar.

        <plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <version>2.0.6</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <proguardVersion>${proguard.version}</proguardVersion>
                    <obfuscate>false</obfuscate>
                    <injarNotExistsSkip>true</injarNotExistsSkip>
                    <injar>${project.build.finalName}.jar</injar>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                    <addMavenDescriptor>true</addMavenDescriptor>
                    <attach>false</attach>
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                        <lib>${java.home}/lib/jsse.jar</lib>
                        <lib>${java.home}/lib/jce.jar</lib>
                    </libs>
                    <proguardInclude>${project.basedir}/proguard.conf</proguardInclude>
                    <options>
                        <option>-printseeds ${project.build.directory}/proguard-seeds.txt</option>
                        <option>-printusage ${project.build.directory}/proguard-shrinkusage.txt</option>
                        <option>-printmapping ${project.build.directory}/proguard-mapping.txt</option>
                        <option>-printconfiguration ${project.build.directory}/proguard-config.txt</option>
                        <option>-dontobfuscate</option>
                        <option>-keepdirectories</option>
                        <option>-dontskipnonpubliclibraryclasses</option>
                        <option>-dontskipnonpubliclibraryclassmembers</option>
                    </options>                  
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.proguard</groupId>
                        <artifactId>proguard-base</artifactId>
                        <version>${proguard.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

According to documentation for the Proguard Plugin in Maven if you don't specify an outjar parameter it will override the input jar.

http://pyx4me.com/pyx4me-maven-plugins/proguard-maven-plugin/proguard-mojo.html

Setting the configuration option attach to true seems to replace the original project artifact.

http://pyx4me.com/pyx4me-maven-plugins/proguard-maven-plugin/proguard-mojo.html#attach

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM