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

在封闭企业网络中使用Maven镜像运行openapi-generator-cli

问题:OpenAPI Generator CLI无法连接公共Maven仓库,如何配置使用内部镜像?

我尝试用npm运行OpenAPI Generator CLI,但工具提示无法连接search.maven.org。

执行的命令:

npx @openapitools/openapi-generator-cli generate -i .\fail.oas.yaml -g ruby -o .\temp

收到的错误信息:

Unable to query repository, because of: "getaddrinfo ENOTFOUND search.maven.org"

堆栈跟踪:

TypeError: Cannot read properties of undefined (reading 'headers')
at VersionManagerService.printResponseError (C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\main.js:2:15114)
at C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\main.js:2:12422
at C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\node_modules\rxjs\dist\cjs\internal\operators\catchError.js:13:51
at OperatorSubscriber._this._error (C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\node_modules\rxjs\dist\cjs\internal\operators\OperatorSubscriber.js:43:21)
at Subscriber.error (C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\node_modules\rxjs\dist\cjs\internal\Subscriber.js:60:18)
at Subscriber._error (C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\node_modules\rxjs\dist\cjs\internal\Subscriber.js:84:30)
at Subscriber.error (C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\node_modules\rxjs\dist\cjs\internal\Subscriber.js:60:18)
at Subscriber._error (C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\node_modules\rxjs\dist\cjs\internal\Subscriber.js:84:30)
at Subscriber.error (C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\node_modules\rxjs\dist\cjs\internal\Subscriber.js:60:18)
at Subscriber._error (C:\Users\tredfern\AppData\Roaming\npm\node_modules@openapitools\openapi-generator-cli\node_modules\rxjs\dist\cjs\internal\Subscriber.js:84:30)

我处于无外网的封闭网络环境,工具在尝试访问公共Maven仓库。我们有可访问的内部Maven镜像,请问如何配置工具使其使用该镜像?

我的.npmrc配置:

registry=https://xxxxxx/repository/npm-all/ <-- 这是我们的npm镜像
always-auth=true
init-author-name=xxxxx
init-author-email=xxxxx
init-author-url=xxxxx
email=xxxx
_auth=xxxxxxxxx9iNndxaWw=
strict-ssl=false

解决方案

OpenAPI Generator CLI的Node版本本质是调用Java版生成器,需配置Maven镜像相关设置,以下是几种可行方式:

1. 临时设置环境变量

执行生成命令前,先设置MAVEN_MIRROR_URL指向内部镜像:

  • Windows命令行:
set MAVEN_MIRROR_URL=https://你的内部Maven镜像地址/repository/maven-public/
  • PowerShell:
$env:MAVEN_MIRROR_URL="https://你的内部Maven镜像地址/repository/maven-public/"

设置完成后再执行原生成命令即可。

2. 配置本地Maven settings.xml

若已有本地Maven配置文件(路径通常为C:\Users\你的用户名\.m2\settings.xml或~/.m2/settings.xml),添加内部镜像配置:

<settings>
  <mirrors>
    <mirror>
      <id>internal-mirror</id>
      <mirrorOf>central</mirrorOf>
      <url>https://你的内部Maven镜像地址/repository/maven-public/</url>
    </mirror>
  </mirrors>
</settings>

工具会自动读取该配置中的镜像规则。

3. 指定本地或内部镜像中的生成器版本

若不想动态拉取版本,可提前下载对应版本的Java jar包,通过环境变量指定:

  • 指定版本号(需确保内部镜像包含该版本):
set OPENAPI_GENERATOR_VERSION=6.6.0
  • 直接指定本地jar包路径:
set OPENAPI_GENERATOR_JAR_PATH=C:\本地路径\openapi-generator-cli-6.6.0.jar

注意:需确保内部Maven镜像已同步OpenAPI Generator相关包的内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 15:23:09