Obfuscate dependencies to single jar with Proguard

断了今生、忘了曾经 提交于 2019-12-11 05:27:18

问题


I have modular maven application and "module1" depends on "module2" and "module2" depends on "module3" etc.. In module1 I have something like this:

<profile>
<id>obfuscate</id>
<build>
    <plugins>
        <plugin>
            <groupId>com.pyx4me</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <options>
                    <option>-allowaccessmodification</option>
                    <option>-keep public class com.test.Main { *; }</option>
                </options>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                </libs>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard</artifactId>
                    <version>${proguard.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

This creates successfully obfuscated "module1". I want to create single jar with all obfuscated dependencies (obfuscated module1 and module2 etc.). Is it possible?


回答1:


Maven Shade Plugin

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

Check it out here.




回答2:


Try the <assembly> option of the maven-proguard-plugin. Make references to each of the dependencies you wanted bundled into the obfuscated jar. See examples.




回答3:


If you want package dependency jars into your uber jar, use shade plugin! here's an example:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"/>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>


来源:https://stackoverflow.com/questions/17045474/obfuscate-dependencies-to-single-jar-with-proguard

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