Ruby GEM repositories

Quick start

Adding a repository that proxies the standard rubygems.org repository is as simple as adding ruby.gems() to the repositories block. It will now resolve anything in the rubygems group to that repository.

build.gradle
repositories {
    ruby.gems() (1)
}

configurations {
    something {
        canBeResolved = true
    }
}

dependencies {
    something 'rubygems:credit_card_validator:1.3.2' (2)
}
1 Add the repository. You can also substitute ruby.gems() with ruby.coop() if you prefer to use gem.coop.
2 Declare the GEM using group rubygems. This is important as only artifacts in that group will be queries against the default GEMs repository.

And the Kotlin DSL equivalent. (You might need the org.ysb33r.jruby.resolver.kt plugin for this to work).

build.gradle.kts
import org.ysb33r.gradle.jruby.kt.resolver.ruby
val something by configurations.creating

dependencies {
    something("rubygems:credit_card_validator:1.3.2")
}

repositories {
    ruby.gems()
}

Customising GEM repositories

It is possible to configure repositories at custom URLs and also assign custom groups.

build.gradle
repositories {
    ruby.gems('https://other-url') (1)
    ruby.gems('otherGroup', 'https://other-url2') (2)
    ruby.gems('https://other-url3') { (3)
        username = 'my.user.name'
        password = 'my.user.password'
    }
    ruby.gems('otherGroup', 'https://other-url4') {
        username = provider { -> 'my.user.name' }
        password = provider { -> 'my.user.password' }
    }
    ruby.coop() (4)
}
1 Use an alternative URL for the Ruby GEM repository.
2 User a custom group and an alternative URL.
3 Configure authentication. For basic auth configure both username and password. For tokens, only set the password. It will then be sent as a bearer token.
4 Use gem.coop as the Ruby GEM repository.

Artifactory

If you are using Artifactory to host GEM repositories, then you can use this kind of configuration. [1]

ruby.gems("https://artifacts.example.intern/artifactory/api/gems/gems-repos") { (1)
    username = provider { -> repository_username }
    password = provider { -> repository_password }
    useV1Api = provider { -> true } (2)
    downloadPattern = "gems/[artifact]-[revision](-[classifier]).gem" (3)
}
1 Set the URL for your Artifactory repository.
2 Artifactory used V1 protocol, so set it here.
3 Set the correct pattern for GEMs on Artifactory.

Using the Maven GEM repository

The JRuby group support their own Maven proxy repository for GEMs. If you prefer to use that rather than the proxy service inside Gradle, you can configure as follows.

build.gradle
repositories {
    ruby {
        mavengems() (1)
        mavengems('https://goo1') (2)
        mavengems('goo2', 'https://goo2') (3)
    }
}
1 Use the default Maven GEMs proxy.
2 Use a Maven GEMs proxy, located at the given URL.
3 Use a Maven GEMs proxy at a different URL and with a custom group other than rubygems.

1. Torsten Krah provided this example.