0

I'm trying to create an obfuscated fat jar build with maven shaded plugin. My configuration is as follows

<build>
    <!-- To parse properties files under resources folder : -->
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
            </plugin>
            <plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <version>2.3.1</version>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.acme.qpguard.editor.Application</mainClass>
                            </transformer>
                        </transformers>
                        <!-- <minimizeJar>true</minimizeJar> -->
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>6.2.1</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <proguardVersion>4.10</proguardVersion>
                <options>
                    <option>-keep class com.acme.*</option>
                </options>
            </configuration>
        </plugin> 
    </plugins>

</build>

The fat jar creation woks as expected but when I combine it with ProGuard, the process is throwing an error. A bit confused in finding the real cause. The exception is as follows.

    [INFO] proguard jar not found in pluginArtifacts
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 10.923 s
    [INFO] Finished at: 2021-05-20T09:29:35+05:30
    [INFO] Final Memory: 21M/413M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal com.github.wvengen:proguard-maven-plugin:2.3.1:proguard (default) on 
   project qpguard: Obfuscation failed ProGuard (proguard.ProGuard) not found in classpath -> [Help 1]
   org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal 
   com.github.wvengen:proguard-maven-plugin:2.3.1:proguard (default) on project qpguard: Obfuscation 
   failed ProGuard (proguard.ProGuard) not found in classpath
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Obfuscation failed ProGuard (proguard.ProGuard) not found in classpath
        at com.github.wvengen.maven.proguard.ProGuardMojo.getProguardJars(ProGuardMojo.java:910)
        at com.github.wvengen.maven.proguard.ProGuardMojo.execute(ProGuardMojo.java:697)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 20 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Looking forward for any pointers to solve this. Thank you.

kallada
  • 1,829
  • 4
  • 33
  • 64
  • looks like you didn't include the libs? `${java.home}/lib/rt.jar` see https://wvengen.github.io/proguard-maven-plugin/ – sorifiend May 20 '21 at 04:51
  • @sorifiend Thanks a lot, the lib part was missing. This was able to solve some issue, but obfuscation is happening. Now when I run the package the tool is compalining proguard.Proguard is not in the classpath. – kallada May 20 '21 at 14:30
  • Might pay to make a new question with the new error. Did you follow all the instructions in the link above for your scenario? Some setups need two libs and a configuration. – sorifiend May 20 '21 at 14:42
  • @sorifiend Sure, I will be adding a new question. Meantime I have tried yGuard too. But It is not working for me as expected. I have created a question for that too: https://stackoverflow.com/questions/67620826/obfuscating-specific-packages-in-a-fat-jar-maven-project-with-yguard – kallada May 20 '21 at 14:57

0 Answers0