如何使用 bitbucket api v2.0 在 gradle 中添加 bitbucket 私有存储库

How to add bitbucket private repository in gradle with bitbucket api v2.0

我的 gradle 项目已关闭,因为它对 bitbucket repo 有一些依赖,并且 bitbucket v1 api 已被弃用。

我在谷歌上搜索了很多有关如何迁移到 v2 的信息,但没有找到好的解决方案。

gradle中的v1api是这样的:

repositories {
  maven {
        credentials {
            username "$mavenUser"
            password "$mavenPassword"
        }
        url "https://api.bitbucket.org/1.0/repositories/<Team>/<repo>/raw/<branch>"
  }
}
repositories {
  maven {
        credentials {
            username "$mavenUser"
            password "$mavenPassword"
        }
        url "https://api.bitbucket.org/2.0/repositories/<Team>/<repo>/src/<branch>"
  }
}

根据 v2 API 参考,我更新了 url,使用 curl -u username:password https://api.bitbucket.org/2.0/repositories/<Team>/<repo>/src/<branch>/<path> 我可以获取原始数据,但是 gradle 仍然无法正常工作并且始终处于 Received 状态来自服务器的代码 403:禁止

明确指定 basic 身份验证后,gradle 按预期工作

repositories {
  maven {
        credentials {
            username "$mavenUser"
            password "$mavenPassword"
        }
        authentication {
            basic(BasicAuthentication)
        }
        url "https://api.bitbucket.org/2.0/repositories/<Team>/<repo>/src/<branch>"
  }
}

下面是 gradle 文档 If no authentication schemes have been assigned to this repository, a default set of authentication schemes are used based on the repository's transport scheme.