-
Notifications
You must be signed in to change notification settings - Fork 78
Writing your own management task
ml-gradle wraps ml-app-deployer with a number of tasks, but in case you want to do something with the MarkLogic Management API that isn't yet supported by ml-gradle, you can simply write a new Gradle task and use an instance of ManageClient to easily invoke Management API endpoints. The ManageClient wraps an instance of Spring's RestTemplate and is already configured with the connection properties in your gradle.properties file.
The sample-project Gradle file shows an example of how to do this, and an example is shown below as well. This simple example invokes a database endpoint for merging a database, and it utilizes the "postJson" convenience method on ManageClient along with configuration data found in the AppConfig instance returned by "getAppConfig".
task mergeContentDatabase(type: com.marklogic.gradle.task.MarkLogicTask) {
doLast {
getManageClient().postJson("/manage/v2/databases/" + getAppConfig().getContentDatabaseName(), '{"operation":"merge-database"}')
}
}
You can also write a task with custom XQuery code (and perhaps SJS code - it's sent over XCC, I haven't tried SJS yet) by extending XccTask:
task myTask(type: com.marklogic.gradle.task.XccTask) {
xccUrl = "my XCC connection URL here"
xquery = "my XQuery code here"
}
You can use Gradle variables to populate xccUrl - e.g. "${mlUsername}:${mlPassword}@${mlHost}:8000/some-database".