Search code examples
githubgradledependency-management

How do I authenticate with Github when using Gradle source code dependencies?


I'm trying to declare a source dependency in a gradle build. In settings.gradle, I have defined:

sourceControl {
    gitRepository("https://github.com/my-organization/myRepo.git") {
        producesModule("com.jrandrews:my-dependency")
    }
}

In build.gradle, I have declared:

configurations{ application }

dependencies {
    application('com.jrandrews:my-dependency') { 
        version { branch = 'master' }
    }
}

I've tried several variations on the theme to try to declare an auth method and auth properties. "gradle dependencies --stacktrace" always results in a failure of the form:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':dependencies'.
    ...
Caused by: org.gradle.api.GradleException: Could not locate branch 'master' for Git repository at https://github.com/....
    ...
Caused by: org.eclipse.jgit.api.errors.TransportException: https://github.com/***.git: Authentication is required but no CredentialsProvider has been registered
    at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:222)
    at org.eclipse.jgit.api.LsRemoteCommand.call(LsRemoteCommand.java:161)
    at org.gradle.vcs.git.internal.GitVersionControlSystem.getRemoteRefs(GitVersionControlSystem.java:103)
    ... 136 more

There are open bugs on this, apparently, but people seem to be successfully using this dependency system, and I can't believe they're all doing it without authentication. Does anyone know how to declare authentication that this dependency declaration can use?


Solution

  • Unfortunately, it will not work for now.