Data Hub Gradle Plugin

About the Gradle Plugin

Gradle is a third-party tool that automates build tasks outside a GUI.

The Data Hub Gradle Plugin (ml-data-hub) extends the MarkLogic Gradle plugin (ml-gradle) with Data Hub-specific tasks, such as testing flows and verifying results in a continuous integration environment. To run a flow using Gradle, you must be in the directory that contains your project files.

The Data Hub Gradle Plugin (ml-data-hub) also uses ml-gradle to deploy MarkLogic server resources (e.g., databases, users, roles, app servers), according to the configurations in the following Data Hub directories:

  • hub-internal-config (your-project-root/src/main/hub-internal-config)
  • ml-config (your-project-root/src/main/ml-config)

After the project is initialized, all project team members must use the Gradle wrapper in the initialized project to run Gradle tasks. This ensures that everyone uses the same version of Gradle.

Tip: You can view the complete list of available Gradle tasks and their descriptions by running gradle tasks.

Learn more about the default (non-Data Hub) behavior of ml-gradle tasks: ml-gradle Common Tasks or ml-gradle Task Reference .

Creating a Custom Gradle Task

The Data Hub Gradle plugin extends the ml-gradle plugin with Data Hub-specific tasks. You can create your own Gradle tasks to handle your application's requirements that are not supported by either plugin.

When creating your own Gradle tasks:

  • Extend com.marklogic.gradle.task.MarkLogicTask to access methods for writing custom tasks.
  • Obtain a DatabaseClient object to communicate with MarkLogic Server.

    To get a DatabaseClient object that is configured with your Data Hub property settings, you must use one of the methods of the Gradle property hubConfig:

    • To access the Staging database, use hubConfig.newStagingClient().
    • To access the Final database, use hubConfig.newFinalClient().
    • To access the Jobs database, use hubConfig.newJobDbClient().
    • To access the Modules database, use hubConfig.newModulesDbClient().

Example: If your custom task needs to communicate with the STAGING database:

   task myHubTask(type: com.marklogic.gradle.task.MarkLogicTask) {
    doLast {
      def client = hubConfig.newStagingClient()
      ...
    }
  }

Extending an ml-gradle Task

You can also extend ml-gradle tasks, including tasks that use MarkLogic's Data Movement SDK (DMSDK), by adding new tasks to the build.gradle file. To use Data Hub property settings, you must configure a DatabaseClient instance for each task.

Example: To delete large collections of data in the FINAL database, add the following code to build.gradle:

   task deleteFinalCollection(type: com.marklogic.gradle.task.datamovement.DeleteCollectionsTask) {
    client = hubConfig.newFinalClient()
    ...
  }

To run your custom task:

./gradlew deleteFinalCollection -Pcollections=my-collection -igradlew.bat deleteFinalCollection -Pcollections=my-collection -i