4

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>"
  }
}
Kan
  • 53
  • 1
  • 6

1 Answers1

11
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.

ahunigel
  • 126
  • 1
  • 4
  • Thanks for your quick response, my credentials is correct without any problem. I have worked it out and please see my updated answer. – ahunigel Jun 12 '19 at 08:50
  • Can you run the job with `-d` for debug output and verify that the correct credentials are being used? – Marcus Held Jun 12 '19 at 08:55
  • I have updated the answer, the question is about how gradle use the credentials, I don't know why it works for bitbucket api v1, but for v2 API, we might have to specify `basic` auth explicitly – ahunigel Jun 12 '19 at 08:59
  • im not sure why but the only way I could get it working is to use my bitbucket credentials (email & password) in place of the maven user credentials. Based on your answer aren't I suppose to use maven user & password? @ahunigel – Creeptosis Nov 28 '19 at 08:36
  • How can you add the implementation in build.gradle after youve added the reopsitory credentials and info? My lib is in maven java. – chitgoks Jan 23 '22 at 10:44
  • What is `mavenUser` and `mavenPassword` here? @ahunigel – Abdul Mateen Jun 30 '22 at 22:56