Zelix KlassMaster - Documentation
 

Calling Zelix KlassMaster™ from Gradle

Zelix KlassMaster™ exposes a generic Java API that allows it to be called by a build tool. A basic Gradle plugin for the Zelix KlassMaster™ obfuscator is built on this API and can be downloaded as zkm-gradle-plugin-1.0.0.zip. An example of how to use the Gradle plugin can be downloaded as zkm-gradle-plugin-use-1.0.0.zip.

The plugin

The plugin can be built and installed with the following command.

gradle build install

Note that the ZKM_JAR_PATH property in the gradle.properties must be set to the path to your Zelix KlassMaster™ distribution's ZKM.jar file. Also note that the JAVA_HOME environment variable may need to be set.

Using the plugin

Once the plugin has been installed, it can be used with the following command.

gradle zkmTask

As mentioned above, an example of how to use the Gradle plugin can be downloaded as zkm-gradle-plugin-use-1.0.0.zip. Note that the ZKM_JAR_PATH property in the gradle.properties must be set to the path to your Zelix KlassMaster™ distribution's ZKM.jar file. Also note that the JAVA_HOME environment variable may need to be set.

An example build.gradle, gradle.properties and ZKM Script for using the plugin are shown below.

Example build.gradle

apply plugin: 'com.zelix.gradle.plugin'

zkmSetting {
    scriptName = "/Projects/myScript.txt" //Must be set to the ZKM Script to execute.
	
    /* Optionally can also set the following.  They are shown with their default settings.
       logFileName = "ZKM_log.txt"
       trimLogFileName = "ZKM_TrimLog.txt"
       defaultExcludeFileName = "defaultExclude.txt"
       defaultTrimExcludeFileName = "defaultTrimExclude.txt"
       defaultDirectoryName
       isVerbose = true
       isParseOnly = false
       extraProperties = new Properties()
    */
}

buildscript {
    repositories {
        mavenLocal()
    }
    dependencies {
        classpath files("$ZKM_JAR_PATH") //ZKM_JAR_PATH must point to your ZKM.jar
        classpath 'com.zelix.gradle:plugin:1.0.0'
    }
}

Example gradle.properties

#ZKM_JAR_PATH must be set to point to your ZKM.jar
ZKM_JAR_PATH=/Projects/ZKM.jar
#Other properties that are set here will be accessible in the ZKM Script
CLASSPATH_LIBS=/libs/Jar0.jar;/libs/Jar1.jar
OPEN_DIR=/Projects
JAR_FILE_TO_OBFUSCATE=MyJarFile.jar
IS_KEEP_GENERICS=true
SAVE_DIR=/Projects/save

Example ZKM Script

//System variables shown in blue. 
//These will be replaced with corresponding values in System properties or gradle.properties.
classpath "%CLASSPATH_LIBS%"
          ;

open      "%OPEN_DIR%%file.separator%%JAR_FILE_TO_OBFUSCATE%";

trimExclude *.*^ public static main(java.lang.String[]);

trim;

exclude     *.^*^ public static main(java.lang.String[]);

obfuscate   keepInnerClassInfo=false
            keepGenericsInfo=%IS_KEEP_GENERICS%
            obfuscateFlow=aggressive
            exceptionObfuscation=heavy
            encryptStringLiterals=flowObfuscate
            ;

saveAll   "%SAVE_DIR%";
 
Documentation Table of Contents