Skip to content
rjrudin edited this page Jun 16, 2015 · 19 revisions

These tasks are present in both ml-gradle 1.* and 2.*.

Automatically load new/modified modules

"gradle mlWatch" - invokes the WatchTask.

This runs an infinite loop, checking every second for modifications in the application's set of module paths. This is a useful task to run when you're developing modules and you only want to load what you've created/modified, and you don't want to have to run a command after every change to load your modules.

See How modules are loaded for information on how modules are actually loaded.

Note that this does not yet account for deleted modules - i.e. it won't delete the corresponding module from the modules database.

Clearing the content database

Call "gradle mlClearContentDatabase" (or usually "gradle mlclearcon") to delete all documents in your content database. You must include the property -PdeleteAll=true. This property is required to decrease the chance that you run this task accidentally.

Clearing the modules database

gradle mlClearModules

Invokes the ClearModulesTask for clearing out all or most of the modules in a modules database. Useful for when you need to do a fresh load of modules because some of the ones in the modules database may have been deleted from your project.

Create a new resource

You can easily create - i.e. stub out - a new REST API resource (or "service") via the following command:

gradle mlCreateResource -PresourceName=sample

The resourceName project property is required; it is used to name the resource file and its namespace. The following files will be created in your project:

  1. src/main/xqy/services/sample.xqy
  2. src/main/xqy/services/metadata/sample.xml

The metadata file is used to provide metadata to the REST API when your resource is installed. You can customize this as you wish.

Create a new transform

You can easily create - i.e. stub out - a new REST API transform via the following command:

gradle mlCreateTransform -PtransformName=sample -PtransformType=xsl

where transformType defaults to "xqy" and can be either "xqy" or "xsl".

This will create the following file in your project:

  1. src/main/xqy/transforms/sample.xqy

Loading modules

gradle mlLoadModules

The purpose of this task is to use the Client REST API to load modules from one or more directory paths. This work of loading modules is handled by the DefaultModulesLoader class found in the ml-java module. See How modules are loaded for more information.

In ml-gradle 2.+, assets - those under /ext - are loaded by XCC by default, as this is typically much faster than loading each module one at a time via the REST API.

By default, this task looks in the src/main/xqy directory for modules to load via the MarkLogic Service Extension REST API. This can be customized in the build.gradle file by modifying the "modulePaths" property in "mlAppConfig" (an instance of AppConfig added by MarkLogicPlugin). For example, a project may have both application modules and test modules that need to be loaded for testing purposes. The build.gradle for such a project would have the following script:

ext {
  mlAppConfig {
    modulePaths = ["src/main/xqy", "src/test/xqy"]
  }
}

Preparing REST API dependencies

gradle mlPrepareRestApiDependencies

The purpose of this task is to take each of the dependencies declared in the "mlRestApi" configuration and unzip them to build directories that are then included in the list of directories configured by mlLoadModules. This task is implemented by PrepareRestApiDependenciesTask.groovy and is registered under mlPrepareRestApiDependencies by MarkLogicPlugin.

This task is very handy when you have dependencies on packages that contain XQuery code that is intended to be installed via the REST API, just like the XQuery code in your project. You typically won't run this task directly (though you're free to do so; it doesn't actually install anything, it just prepares the dependencies for installation). This task is usually executed via mlLoadModules, which depends on it. Note that if you don't have any mlRestApi dependencies declared, then this task won't do anything.

One thing to be aware of - since mlLoadModules expects to find directories to configure in the "modulePaths" list property of "mlAppConfig", this task will add directories to that list.

Here's a sample of an mlRestApi dependency:

dependencies {
  mlRestApi "com.marklogic:sample:1.0"
}

The "prepared" depedencies will be unzipped under "build/mlRestApi" in your project directory.

Reload modules

gradle mlReloadModules

This task simply combines mlClearModules and mlLoadModules together. This is useful to invoke when you want to ensure you have a clean modules database - i.e. some modules may have been deleted from your version control system, but they're still hanging out in your modules database.

Clone this wiki locally