1

我正在使用带有 corb2 2.4.5 和 Marklogic 9.0.5 的 ml-gradle。

我试图在运行 gradle 任务时将参数传递给 corb。我已将参数传入

-DURIS-MODULE.id="sf"

在我的 xquery 模块中,我有

declare variable $id as xs:string external;

corb 进程运行,但它不设置 id 变量。我需要改变什么才能使这项工作?

4

2 回答 2

2

执行 ml-gradle CoRB 任务时,应设置所有系统属性并将其传递给您的 CoRB 作业。

我怀疑您可能正在运行旧版本的 ml-gradle,或者您的工作中可能存在其他问题。

我已经验证我可以通过执行以下命令将外部 URIS-MODULE 变量传递给这个简化的作业:

gradle -DURIS-MODULE.id=2 -DURIS-MODULE="INLINE-XQUERY|declare variable $id external;concat('PROCESS-MODULE.id=',string($id)),1,1|ADHOC" -DPROCESS-MODULE="INLINE-XQUERY|declare variable $id external;xdmp:log(concat('process module id=',$id))|ADHOC" corb

我看到我的应用程序服务器错误日志包括以下行:

2020-03-12 09:23:44.198 Info: process module id=2

ml-gradle CoRB 任务收集所有系统属性并在任务运行时将它们传递给 CoRB:

https://github.com/marklogic-community/ml-gradle/blob/master/src/main/groovy/com/marklogic/gradle/task/CorbTask.groovy#L102

Map options = buildCorbOptions()
//CoRB2 will evaluate System properties for options
systemProperties(options)

super.exec()

buildCorbOptions()方法 https://github.com/marklogic-community/ml-gradle/blob/master/src/main/groovy/com/marklogic/gradle/task/CorbTask.groovy#L121 _

  /**
  * Construct CoRB2 options from the following sources:
  * task variables - lowerCamelCase names that correspond to their CoRB2
  *                  option (i.e. optionsFile => OPTIONS-FILE)
  * project properties - Project properties with the naming convention
  *                      of a 'corb' prefix and CamelCased CoRB2 option name
  *                      (i.e. corbOptionsFile => OPTIONS-FILE)
  * System properties - Any System property with a CoRB2 option name
  *
  * If properties are defined in more than one place, System properties will take
  * precedence over Project properties, which take precedence over task member variables.
  *
  * @return Map of CoRB2 options
  */
  public Map buildCorbOptions() {
    //first, convert legacy task properties and generate options from conventions
    Map options = collectNormalizedOptions()
    //collect all of the corb task options (i.e. threadCount=12)
    options << collectMemberVariables()
    //apply any corb project properties (i.e. -PcorbThreadCount=12)
    options << collectCorbProjectProperties()
    //apply any CoRB2 System properties (i.e. -DTHREAD-COUNT=12)
    options << collectSystemProperties()
    options //return the merged options
  }

调用collectSystemProperties()方法:

  /**
  * Collect all System.properties. This allows for any CoRB option to be set, including those not statically known such
  * as CoRB custom inputs (e.g. URIS-MODULE.foo, PROCESS-MODULE.bar, etc) as well as settings for other libraries, such
  * as xcc.httpCompliant to enable XCCS compatability for XCC.
  * @return all System.properties
  */
  public Map collectSystemProperties() {
    System.properties
  }
于 2020-03-12T13:28:11.180 回答
0

请务必使用 type CorbTask,而不是 Java 任务,以利用参数处理。

利用:

task some-corbCorbTask(type: com.marklogic.gradle.task.CorbTask) {...}

而不是:

task some-corbJAVA(type: Java) {...}
于 2020-06-12T10:36:36.323 回答