首页 > 解决方案 > 如何使用 bitbucket api v2.0 在 gradle 中添加 bitbucket 私有存储库

问题描述

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

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

gradle 中的 v1 api 是这样的:

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

标签: javagradlebitbucket-api

解决方案


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 仍然无法正常工作,并且总是从服务器收到状态代码 403:Forbidden

明确指定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.


推荐阅读