0

I'm trying to invoke yGuard Ant task from Gradle:


ant.taskdef(name:'yguard', classname:'com.yworks.yguard.YGuardTask', classpath: '../yguard/yguard-2.9.2.jar;../yguard/retroguard-2.9.2.jar;../yguard/guava-28.1-android.jar;../yguard/asm-7.2.jar')
ant.yguard {
    inoutpair(in: 'in.jar', out: 'out.jar')
    attribute(name:'Deprecated, SourceFile, LineNumberTable, LocalVariableTable, LocalVariableTypeTable')
    rename(mainclass:"com.....z.Z",logfile:"obfuscation.log",replaceClassNameStrings:"true") {
        keep {
            class(implements:"java.io.Serializable",classes:"private",methods:"private",fields:"private") {
                patternset {
                    include name:"org.**.*"
                    include name:"com.google.**.*"
                    include name:"com.sun.**.*"
                    // ...
                }
            }
        }
    }
}

I'm quite used to invoke Ant from Gradle, but here I'm stuck on the tag name which is named <class .../>. Of course Groovy confused with the getClass() method.

I've tried the following alternative (as suggested here: Gradle - how to run ant task with "-" in name): ant.class => same ant."class" => don't know what it does, but doesn't work :) But it is still confusing with getClass() method I think

of course, there is the following solution:

  • use ant.importBuild instead, to write XML instead of groovy scripts, but it would be too easy ;) And I'd would really like to stay in groovy/gradle DSL if possible
  • I could use yGuard gradle plugin instead, but I encountered problems

The example with yGuard is just an example. I would really love to understand which mechanism is used underneath, and how to enforce the behavior I want (Groovy is so powerful, I'm pretty sure, there is a way)

Christophe Moine
  • 816
  • 1
  • 7
  • 7

1 Answers1

0

Sorry, in the end:

ant.class AND ant."class" is working. I hope the complete sample can help someone else to translate his ant script to Gradle!

    ant.taskdef(name:'yguard', classname:'com.yworks.yguard.YGuardTask', classpath: '../yguard/yguard-2.9.2.jar;../yguard/retroguard-2.9.2.jar;../yguard/guava-28.1-android.jar;../yguard/asm-7.2.jar')
    ant.yguard {
        inoutpair(in: 'in.jar', out: 'out.jar')
        attribute(name:'Deprecated, SourceFile, LineNumberTable, LocalVariableTable, LocalVariableTypeTable')
        rename(mainclass:"com.....z.Z",logfile:"obfuscation.log",replaceClassNameStrings:"true") {
            keep {
                ant.class(classes:"private",methods:"private",fields:"private") {
                    patternset {
                        include name:"org.**.*"
                        include name:"com.google.**.*"
                        include name:"com.sun.**.*"
                        // ...
                    }
                }
            }
        }
    }

original ant script:


    <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="yguard/yguard-2.9.2.jar;yguard/retroguard-2.9.2.jar;yguard/guava-28.1-android.jar;yguard/asm-7.2.jar" />
            <yguard>
                <inoutpair in="in.jar" out="out.jar"/>
    
                <!-- Keep all of the attributes for debugging, e.g. -->
                <attribute name="Deprecated, SourceFile, LineNumberTable, LocalVariableTable, LocalVariableTypeTable" />
    
                <rename mainclass="com.....z.Z" logfile="obfuscation.log" replaceClassNameStrings="true">
                    <keep>
                        <class classes="private" methods="private" fields="private">
                            <patternset>
                                <include name="org.**.*" />
                                <include name="com.google.**.*" />
                                <include name="com.sun.**.*" />
                                <include name="com.thoughtworks.**.*" />
                                <!-- ... -->
                            </patternset>
                        </class>
                    </keep>
                </rename>
            </yguard>

the machinery behind all this still hold though ;-) I had a look into DefaultAntBuilder source code, but not much help.

Christophe Moine
  • 816
  • 1
  • 7
  • 7