Can I get plugins from an Artifactory which requires HTTP basic auth?

I’m trying to run a gradle build within a heavily firewalled corporate environment. I’ve set up an Artifactory which proxies the Gradle Maven plugin repo ( https://plugins.gradle.org/m2/ ).

I’m unable to resolve plugins when I try to run my build. Can you help me correct my settings file so that I can get this build operational?

I’ve created a settings.gradle file with the following content:

pluginRepositories {
    maven {
        url 'http://artifactory.bigco.com:8081/artifactory/virtual-gradle/gradle/plugin/'
        credentials {
            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
    }
}

The first strange thing is that my IDE (IntelliJ) gives me a warning: ‘credentials’ cannot be applied to GString? That seems to suggest that I’m not allowed to have a credentials block inside a maven block in settings.gradle.

If I look at the URL that I’ve used for this repo, it contains two directories: “org” and “com”.

When I run the build I get the following error:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\workspace\fooproject\build.gradle' line: 26

* What went wrong:
Plugin [id: 'org.jenkins-ci.jpi', version: '0.16.0'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- maven(http://artifactory.bigco.com:8081/artifactory/virtual-gradle/gradle/plugin/) (Could not resolve plugin artifact 'org.jenkins-ci.jpi:org.jenkins-ci.jpi.gradle.plugin:0.16.0')

This is just IntelliJ being overly strict in type checking. Technical a GString (i.e. “foo”) is not compatible with String (i.e. ‘foo’) but type coercion sorts this out for us in the buildscript.

Mirroring the Gradle plugin portal is currently not possible when using the plugins { } syntax. The only way to mirror that repository and use plugins from it is using the old buildscript { } syntax. This is a known limitation which we hope to remove soon.

Is there an example of the buildscrpt syntax I can use? I need to set up access to a private mirror which uses HTTP basic auth.

It would look something like this:

buildscript {
  repositories {
    maven {
      url 'http://artifactory.bigco.com:8081/artifactory/virtual-gradle/gradle/plugin/'
      credentials {
        username = "${artifactory_user}"
        password = "${artifactory_password}"
      }
    }
  }
  dependencies {
    classpath "gradle.plugin.org.jenkins-ci.tools:gradle-jpi-plugin:0.22.0"
  }
}

apply plugin: "org.jenkins-ci.jpi"