-
Notifications
You must be signed in to change notification settings - Fork 77
Writing your own command
As discussed in Writing your own management task, you can easily add new Gradle tasks to do anything that you would like with the MarkLogic Management API.
But, in some cases, you'll want to insert new steps in the middle of the deployment process as executed by "gradle mlDeploy". This task invokes the "deploy" method on an instance of AppDeployer, which defaults to SimpleAppDeployer. SimpleAppDeployer invokes a list of Command objects in an order based on the "getExecuteSortOrder" method defined in that interface. Thus, to add a new step to the deployment process, you just need to do the following:
- Create a new implementation of the Command interface. You can do this inline in your Gradle build file, or you can define it as a class file in your Gradle buildSrc directory. You may want to start by subclassing AbstractCommand.
- Add an instance of your Command implementation to the SimpleAppDeployer that's created by MarkLogicPlugin.
Now, when you run "gradle mlDeploy", your command will be executed. If you need to perform some cleanup work during "gradle mlUndeploy", then just make your Command implementation implement UndoableCommand.
For an example of this, see the custom command class that's defined in the sample-project Gradle build file.