July 13, 2012

[Maven Obfuscation]Using yguard




<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>yguard</groupId>
<artifactId>yguard</artifactId>
<version>2.1.0</version>
<scope>system</scope>
<systemPath>${basedir}/../lib/yguard.jar</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<property refid="maven.compile.classpath" name="mvn.classpath"></property>
<!-- <echo message="Using Maven Classpath: ${mvn.classpath}" /> -->
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" />
<yguard>
<!-- Input file and output file is the same. -->
<inoutpair
in="${project.auto.deploy.dir}/jar/${project.build.finalName}.${project.packaging}"
out="${project.auto.deploy.dir}/jar/${project.build.finalName}_obfuscation.jar" />

<shrink logfile="${project.auto.deploy.dir}/yguard.log.xml">
<property name="error-checking" value="pedantic"/>
<keep>
<class classes="public" methods="public">
<patternset>
<include name="*" />
</patternset>
</class>
</keep>
</shrink>
<!-- Obfuscate classes plus string references. -->
<rename  mainclass="com.pkg.edi.MainParser" logfile="${project.auto.deploy.dir}/yguard.log.xml"
replaceClassNameStrings="true">
<property name="error-checking" value="pedantic"/>
<!-- Keep the only class to be used for easy running and its public 
method main(). 
-->

<adjust replaceContent="true">
       <!-- plain-text class names in the config files will -->
       <!-- be replaced with the obfuscated name versions -->
       <include name="**/*.xml"/>
       <include name="**/*.properties"/>
      </adjust>
       <!-- <adjust replacePath="false">
       keep the complete path to the resources, (gifs...) even if
       package com.mycompany.myapp gets obfuscated by name
       <include name="com/pkg/persistence/*"/>
       </adjust> -->
       <adjust replaceName="true">
       <!-- Replace the .properties files' names with the obfuscated -->
       <!-- versions if the corresponding .class files get obfuscated -->
       <include name="**/*.properties"/>
       </adjust>

<keep>
 
<class classes="public" methods="public">
<patternset>
<include  name="com.pkg.edi.MainParser" />
</patternset>
</class>
</keep>
</rename>

<!-- There are some external libraries used - Maven knows details. -->
<externalclasses>
<pathelement path="${mvn.classpath}" />
</externalclasses>
</yguard>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

5 comments: