Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

My gradle project is down because it has some dependencies on bitbucket repo and the bitbucket v1 api was deprecated.

I've googled a lot about how to migrate to v2 but doesn't find a good solution.

The v1 api in gradle is like this:

repositories {
  maven {
        credentials {
            username "$mavenUser"
            password "$mavenPassword"
        }
        url "https://api.bitbucket.org/1.0/repositories/<Team>/<repo>/raw/<branch>"
  }
}
like image 975
Kan Avatar asked Sep 19 '25 09:09

Kan


1 Answers

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

According to v2 API reference, I updated the url, and with curl -u username:password https://api.bitbucket.org/2.0/repositories/<Team>/<repo>/src/<branch>/<path> I can get raw data, but gradle still not works and always Received status code 403 from server: Forbidden

After specify basic authentication explicitly, gradle works as expected

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

Below is gradle documentation 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.

like image 139
ahunigel Avatar answered Sep 20 '25 23:09

ahunigel