I'm trying to obfuscate my generated project JAR file with no success. So I tried to reduce all the steps in order to find out what is going on and I've realized that I cannot use yguard at all and I don't know why. Maybe is an eclipse bad configuration...

I added the yguard in my pom.xml

        <dependency>
            <groupId>com.yworks</groupId>
            <artifactId>yguard</artifactId>
            <version>3.0.0</version>
        </dependency>

And I added in the pom.xml and excution (during packaging) that tries to obfuscate a single JAR file

<execution>
    <id>Obfuscate</id>
    <phase>package</phase>
    <goals>
        <goal>run</goal>
    </goals>
    <configuration>
        <tasks>
            <property name="runtime-classpath" refid="maven.runtime.classpath"/>
            <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${runtime-classpath}"/>
            <yguard>
                <inoutpair in="C:/test/example.jar" out="C:/test/example_obfuscated.jar" />
                <shrink/>
            </yguard>
       </tasks>
    </configuration>
</execution>

"example.jar" is properly placed in "C:/test" and is simply a class file generated manually (in order to simplify my obfuscation test).

jar cf example.jar myClass.class

When I run any MAVEN process that includes the package phase, the execution fails and I receive the following console message:

main:
   [shrink] yGuard Shrinker v3.0.0 - http://www.yworks.com/products/yguard
   [shrink] no entrypoints given - using class access public and protected on all inoutpairs.
   [shrink] ERROR: class com.yworks.yshrink.model.ModelVisitor has interface org.objectweb.asm.ClassVisitor as super class
   [shrink] class com.yworks.yshrink.model.ModelVisitor has interface org.objectweb.asm.ClassVisitor as super class
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 26.382 s
[INFO] Finished at: 2022-01-20T14:32:24+01:00
[INFO] Final Memory: 54M/714M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (Obfuscate) on project grb: An Ant BuildException has occured: yShrink encountered an unknown severe problem!
[ERROR] around Ant part ...<yguard>... @ 6:11 in C:\espacio_trabajo_7\eclipse\eclipse_2019-09\workspace\trunk\grb\target\antrun\build-main.xml: class com.yworks.yshrink.model.ModelVisitor has interface org.objectweb.asm.ClassVisitor as super class
[ERROR] -> [Help 1]`

Any idea? I really appreciate any help you can provide.

Ivan

1

There are 1 best solutions below

0
Ivan On

Problem was related to other libraries that uses the asm artifact too. So I had to do the following:

1- Exclude asm from yguard

2- Add asm to my pom.xml

3- Exclude all the asm references from other libraries (in my case 2 libraries): 1- jasperreports used itext and olap4j that both used asm 2- retroweaver

4- Add manually the excluded libraries

    <dependency>
        <groupId>com.yworks</groupId>
        <artifactId>yguard</artifactId>
        <version>3.0.0</version>
        <exclusions> 
            <exclusion>
                 <groupId>org.ow2.asm</groupId>
                 <artifactId>asm</artifactId>
            </exclusion>    
        </exclusions>           
    </dependency>       
    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm</artifactId>
        <version>7.2</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>6.4.1</version>                    
        <exclusions> 
            <exclusion>
                 <groupId>com.lowagie</groupId>
                 <artifactId>itext</artifactId>
            </exclusion>
            <exclusion>
                 <groupId>org.olap4j</groupId>
                 <artifactId>olap4j</artifactId>
            </exclusion>                                                    
        </exclusions>                                   
    </dependency>       
    <dependency>
        <groupId>net.sourceforge.retroweaver</groupId>
        <artifactId>retroweaver</artifactId>
        <version>1.2.4</version>    
        <exclusions> 
            <exclusion>
              <groupId>asm</groupId>
              <artifactId>asm</artifactId>
            </exclusion>    
        </exclusions>                           
    </dependency>       
    <dependency>
        <groupId>org.olap4j</groupId>
        <artifactId>olap4j</artifactId>
        <version>0.9.7.309-JS-3</version>
        <exclusions> 
            <exclusion>
                 <groupId>net.sourceforge.retroweaver</groupId>
                 <artifactId>retroweaver</artifactId>
            </exclusion>
            <exclusion>
                <groupId>asm</groupId>
                <artifactId>asm</artifactId>
            </exclusion>                                                                    
        </exclusions>           
    </dependency>