Skip to content

Support authentication credentials in URL returned from rootUrlMapper #3

@cjp0tter

Description

@cjp0tter

Hi There. We use an internal Sonatype Nexus artifact repository for managing internal and third party dependencies. I'd like to be able to provide credentials in the URL returned from the rootUrlMapper so the download can leverage authentication. See proposed change below.

private static void download(Project project, String fromUrl, File toFile) {
    def url = new URL(fromUrl)
    def urlConnection = url.openConnection();

    if (url.getUserInfo() != null) {
       def basicAuth = "Basic " + new String(new Base64().encode(url.getUserInfo().getBytes()));
       urlConnection.setRequestProperty("Authorization", basicAuth);
    }

    def from = Channels.newChannel(urlConnection.getInputStream())
    project.logger.lifecycle("About to download a gradle distribution from $fromUrl to $toFile.absolutePath")
    new FileOutputStream(toFile).withCloseable {
        it.channel.transferFrom(from, 0, Long.MAX_VALUE)
    }
    project.logger.lifecycle("Downloaded a gradle distribution from $fromUrl to $toFile.absolutePath")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions