3

Ok, I'm trying to compile dependency on remote maven url (bitbucket). The problem is that i can't pass bitbucket authentication on that stage. I've tried this:

repositories{
  maven{ url "https:" + "${username}" + ":" + "${password}" + ...etc}
}

And it doesn't work for me. So i've enabled and connected via SSH. The question is: how to compile dependency from remote private maven repository (hosted on bitbucket) using SSH?

Rishka
  • 413
  • 5
  • 16

2 Answers2

6

with my team were facing the same exact issue and we ended up solving it with the bitbucket REST API. So putting the following code in the build.gradle file (in the project root)

allprojects {
  repositories {
    maven {
      url 'https://api.bitbucket.org/1.0/repositories/REPO_OWNER/REPO_NAME/raw/BRANCH_NAME'
    }
    credentials {
      username bitbucket_username
      password bitbucket_password
    }
  }
}

Where the REPO_OWNER is your bitbucket username or the team name that owns the repo, REPO_NAME as you already know is the name of the repository you want to get the lib from and BRANCH_NAME the branch name.

Moreover the bitbucket_username and the bitbucket_password are defined in the gradle.properties in the following way:

bitbucket_username = yourBitbucketUsername
bitbucket_password = yourBitbucketPasword

Please notice that the username and the password are not written with any quote symbol.

I hope it will work for you!

Eric Borland
  • 111
  • 4
  • You have a typo in Your post. You mean **gradle.properties** for sure. :) – Tomasz Dzieniak Mar 03 '16 at 23:02
  • I use same url time ago and it works fine. But may be pretty hide the password if you want distribute the code partially to a client and that they could compile the code... I don't know if its possible using SSH. – wendigo Mar 08 '16 at 20:46
  • @wendingo We tried with SSH long time ago with no success... Unfortunately I'm not anymore with gradle nor maven so I'm afraid I'm not helpful anymore... We use to have two files and never pushing our own credentials to the repo, but of course that won't work if you need your client to access to it... – Eric Borland Mar 14 '16 at 14:34
  • @tommus yup, you're right, I was meaning gradle.properties thx – Eric Borland Mar 14 '16 at 14:37
1

From the dependency management section of the gradle documentation:

repositories {
    maven {
        url "sftp://repo.mycompany.com:22/maven2"
        credentials {
            username 'user'
            password 'password'
        }
    }
}
Steinar
  • 5,860
  • 1
  • 25
  • 23
  • nope=( It doesn't work for bitbucket. It shows "Already seen doctype" error – Rishka Mar 11 '15 at 12:24
  • [This guy](http://stackoverflow.com/questions/25466407/gradle-build-failing-to-get-dependency-from-custom-maven-repository) seemed to have a similar problem. He fixed it by tweaking the URL to something similar to the one you already tried. Are you sure the URL is correct? Looks like you're missing a couple of "//", but that might just be the post... – Steinar Mar 11 '15 at 12:46
  • ye, if I do it the way as discussed in topic, gradle won't even try to request such url. It says: "target host must not be null". If I try to go through result url in browser (it looks like: "https://username:passwork@bitbucket.org/...."), it won't even pass. It'd google that automatically. Maybe i'm missing something? – Rishka Mar 11 '15 at 13:25