1

I am new to gradle and need to write a task for scheduling MarkLogic backup.

So, I want to invoke an XQuery module that uses a config XML for getting details for backup.

So I tried this :

task mlBackupTask(type: com.marklogic.gradle.task.ServerEvalTask) {
  def client = hubConfig.newStagingClient()
  println client
  //DatabaseClient client = DatabaseClientFactory.newClient(host,portno,new DatabaseClientFactory.DigestAuthContext(username, password))
  ServerEvaluationCall invoker = client.newServerEval();
  String result = invoker.modulePath("/admin/create-backup.xqy").addVariable("config-name", "dev").evalAs(String.class);
}

I tried both :

  • hubConfig.newStagingClient()
  • DatabaseClientFactory.newClient(host,portno,new DatabaseClientFactory.DigestAuthContext(username, password))

This doesn't work and just give this error :

Execution failed for task ':mlBackupTask'. java.lang.NullPointerException (no error message)

Could someone please help out on this?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Shabana
  • 121
  • 7

1 Answers1

2

Start with the docs at https://github.com/marklogic-community/ml-gradle/wiki/Writing-your-own-task . "hubConfig.newStagingClient()" will only work if you're using DHF, as hubConfig is specific to DHF.

Also, I think based on your code, what you really want is to use MarkLogicTask. The purpose of ServerEvalTask is to allow you to write a single line of JS or XQuery code. It looks like you want to write multiple lines of code, given a DatabaseClient. If so, use MarkLogicTask, and also put your code in a "doLast" block as shown in the docs.

rjrudin
  • 2,108
  • 9
  • 7