Add the DashO Java Gradle plugin artifact to the buildscript classpath, apply the plugin that matches your workflow, and configure its dashOConfig closure. All three Java plugins are packaged in the JAR included under the gradle directory in DashO Home.
These instructions apply to JVM-based Java projects. For an Android project built with the Android Gradle Plugin, use the DashO Gradle Plugin for Android.
Apply a Java plugin
Add the gradle directory under DashO Home as a flat-directory repository, add the DashO plugin artifact to the buildscript classpath, and apply one of the three plugins:
buildscript {
repositories {
flatDir dirs: "<DashO Home>/gradle"
}
dependencies {
classpath "com.preemptive:dasho:X.y.+"
}
}
apply plugin: 'com.preemptive.dasho' //or 'com.preemptive.dashoJar', or 'com.preemptive.dashoCustom'Replace <DashO Home> with the directory containing DashOPro.jar. Replace X.y with the plugin version included in that DashO installation.
Configure the plugin
Configure any of the three plugins with the dashOConfig closure. All settings are optional, but the build must be able to determine DashO Home and locate a DashO project file.
dashOConfig {
dashOHome = '<DashO Home>'
doxFilename = 'project.dox'
includeAsInputs = ['myLibrary.jar']
maxHeap = '512M'
verbose = true
debug = false
}| Property | Description |
|---|---|
dashOHome |
Specifies DashO Home. If it is not set in the closure, provide DASHO_HOME as an environment variable or Java system property. |
doxFilename |
Specifies the DashO project file. The default is project.dox. |
includeAsInputs |
Lists support JARs that DashO should process as inputs. Each file must already be on the Gradle compile classpath. |
maxHeap |
Sets the maximum heap for the DashO process. Supported units are G, M, K, and B. A value without a unit is interpreted as mebibytes. Available in plugin 1.7 and later. |
verbose |
Runs DashO with --verbose and --printStackTraces. In plugin 3.1.2 and later, it also enables SHOW_DASHO_CMD. Available in plugin 2.3.4 and later. |
debug |
Runs DashO with --debug and enables verbose output. Available in plugin 3.2.0 and later. |
Configure the DashO project file
The Java plugins pass build paths to DashO as user properties. Configure the DashO project file to use:
-
${gradleInput}for the input location. -
${gradleOutput}for the output location. -
${gradleSupport}for the support classpath.
The output type in the DashO project must match the selected plugin or custom task:
| Plugin or task | Required DashO output |
|---|---|
com.preemptive.dasho or DashODirTask
|
Merged directory |
com.preemptive.dashoJar |
JAR |
DashOFileTask |
File type required by the custom task, such as JAR or APK |
Enable protection with com.preemptive.dasho
When you apply both the standard Gradle Java plugin and com.preemptive.dasho, the DashO plugin adds an obfuscate task before Gradle packages the JAR. The resulting JAR contains the protected classes.
The obfuscate task runs when you run either of the following:
gradlew jargradlew buildEnable protection with com.preemptive.dashoJar
The com.preemptive.dashoJar plugin adds an obfuscateJar task after Gradle creates the JAR. The task writes the protected JAR to the obfuscated_libs directory under the build output.
Run the task directly:
gradlew obfuscateJarThe task also runs as part of:
gradlew buildCreate a custom DashO task
Apply com.preemptive.dashoCustom when the integrated task behavior does not fit your build. This plugin adds no tasks automatically. Define a task with one of the provided task types:
-
DashODirTaskprocesses a directory and writes a directory. -
DashOFileTaskprocesses a file, such as a JAR or APK, and writes a file.
Configure the task input with from, the output with to, and the support classpath with setSupportClasspath. Use addUserProperty to pass additional user properties to DashO.
task myCustomDashOTask(type: DashODirTask) {
from("$MyInputDirectory")
to("$MyOutputDirectory")
setSupportClasspath("$MyClasspath")
addUserProperty("MyPropertyName", "MyValue")
}Format the support classpath with the operating system's path separator.
Verify that DashO runs
Run the Gradle task that includes DashO protection. When the task runs, the console output identifies the DashO version.
You can also list the available tasks:
gradlew tasks --allDepending on the applied plugin, verify that obfuscate, obfuscateJar, or your custom DashO task appears.
If the task does not appear or DashO does not run, review Gradle Plugins for Java Troubleshooting.
Configure the license
In Java Gradle plugin 5.0.0 and later, provide the DashO license string through the DASHO_LICENSE Gradle project property, Java system property, or environment variable.
For example:
gradlew build -PDASHO_LICENSE={key[:email]}To provide it through an environment variable as a Gradle project property, prefix the name with ORG_GRADLE_PROJECT_:
ORG_GRADLE_PROJECT_DASHO_LICENSE={key[:email]}A Java property can be set on the command line as a -D argument (e.g. -DDASHO_LICENSE={key[:email]}).