You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Gradle部署代码至MarkLogic Server时遭遇401 Unauthorized错误

Gradle部署MarkLogic遇401未授权错误的解决办法

问题场景

用Gradle部署代码到MarkLogic Server(版本10.0-9.4),执行命令:

./gradlew mlDeploy -i -PmlUsername= -PmlPassword= -PmlHost=""

触发以下错误:

Sending XML GET request as user 'admin' (who should have the 'manage-admin' and 'security'roles) to path: /manage/v2/privileges Logging HTTP response body to assist with debugging: {"errorResponse":   {"statusCode":401,"status":"Unauthorized","message":"401 Unauthorized"}}

当前build.gradle配置如下:

plugins {
    // node
    id "com.moowork.node" version "1.1.1"
    // ML-Gradle will handle the marklogic configuration
    id 'com.marklogic.ml-gradle' version '4.1.0'
}

repositories {
    mavenCentral()
    // Needed for mlcp dependencies
    maven { url 'https://developer.marklogic.com/maven2/' }
}

configurations {
    mlcp
}

dependencies {
    mlcp 'com.marklogic:mlcp:10.0.5'
    mlcp files('lib')
}

// Control nodejs and NPM build tasks via gradle

node {
    // Version of node to use.
    version = '4.8.4'
    npmVersion = '5.4.2'
    download = true
}

问题根源

  1. 执行命令时-PmlUsername和-PmlPassword未传入有效值,ML-Gradle默认使用admin用户,但没有提供匹配的密码,导致身份验证失败。
  2. mlHost参数留空,可能导致请求无法正确发送到MarkLogic服务器,间接影响认证流程。

解决步骤

1. 补全命令中的认证参数

执行命令时,填入MarkLogic的有效用户名、密码和主机地址,示例:

./gradlew mlDeploy -i -PmlUsername=admin -PmlPassword=你的Admin密码 -PmlHost=localhost

注:主机地址根据实际情况填写,比如服务器IP或域名,不要留空。

2. 配置Gradle属性文件(更便捷)

避免每次命令输入参数,可在项目根目录创建gradle.properties文件,添加以下内容:

mlUsername=admin
mlPassword=你的密码
mlHost=localhost

之后直接执行命令即可:

./gradlew mlDeploy -i

提示:不要把gradle.properties提交到版本控制,防止密码泄露。

3. 确认用户权限

确保使用的用户拥有manage-admin和security角色,admin用户默认自带这些角色;如果使用自定义用户,需登录MarkLogic管理控制台检查角色分配。

内容的提问来源于stack exchange,提问作者ravvi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 04:10:35