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

如何将Flutter本地Maven仓库的AAR包上传至远程Maven仓库?

解决Flutter AAR推送远程Maven仓库的参数缺失问题

你遇到的错误是因为mvn deploy:deploy-file命令缺少两个关键参数:远程仓库地址-Durl和仓库身份ID-DrepositoryId,个别情况还可能存在pom文件无对应AAR的情况,导致file参数无效。以下是具体解决方法:

1. 修正原find命令,补充必要参数

将原命令修改为以下形式,替换其中的仓库地址和ID为你的实际信息:

find . -name "*.pom" -type f -exec sh -c '
  # 拼接对应的AAR文件路径
  AAR_FILE="${0%.pom}.aar"
  # 先检查AAR文件是否存在,避免无效执行
  if [ -f "$AAR_FILE" ]; then
    mvn deploy:deploy-file \
      -DpomFile="$0" \
      -Dfile="$AAR_FILE" \
      -Durl="https://your-maven-repo-url.com/repository/releases/" \
      -DrepositoryId="maven-releases"
  else
    echo "警告:未找到pom文件 $0 对应的AAR文件 $AAR_FILE"
  fi
' '{}' \;

参数说明:

  • -Durl:远程Maven仓库的具体地址,区分release和快照仓库,比如快照仓库地址通常是https://xxx/repository/snapshots/
  • -DrepositoryId:对应本地Maven配置文件~/.m2/settings.xml中<server>节点的id值,用来读取仓库的用户名和密码做权限验证

2. 配置Maven仓库权限

在~/.m2/settings.xml的<servers>节点下添加远程仓库的身份验证信息:

<server>
  <id>maven-releases</id> <!-- 这里的id要和命令中的-DrepositoryId一致 -->
  <username>你的仓库用户名</username>
  <password>你的仓库密码</password>
</server>

3. 可选:过滤特定变体的AAR

如果只需要推送release版本的AAR,可以给find命令添加路径过滤:

find . -path "*release*.pom" -name "*.pom" -type f -exec sh -c '
  AAR_FILE="${0%.pom}.aar"
  if [ -f "$AAR_FILE" ]; then
    mvn deploy:deploy-file \
      -DpomFile="$0" \
      -Dfile="$AAR_FILE" \
      -Durl="https://your-maven-repo-url.com/repository/releases/" \
      -DrepositoryId="maven-releases"
  fi
' '{}' \;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 07:17:43