Build Your Own Tooling

Sometimes you might want to utilise (J)Ruby-based tools with your own plugins, but you do not want to directory expose everything that might be available in other plugin in this suite. You can use the core functionality that exists within the resolver plugin to build your own tooling.

A task to prepare GEMs

The easiest way to implement your own GEM resolver is to extend AbstractGemPrepareTask.

@CompileStatic
class MyPrepareTask extends AbstractGemPrepareTask {
    @Inject
    MyPrepareTask(WorkerExecutor we) {
        super(we)
    }
}

You also need to apply the resolver plugin and then instantiate your task within your plugin.

String name = 'myGems' (1)
project.pluginManager.apply(JRubyResolverPlugin)
project.extensions.getByType(GemConfigurations).register(name, MyPrepareTask)
1 Set a name for the configuration that will hold the GEMs (and associated JARs).

Resolving the JRuby JAR

It is necessary to set a provider for the jruby-complete JAR which will needed to run the preparation task. The easiest is to use an existing instance of JRubyExtension or to attach such an extension to your task. The following example shows you how to create such an extension, which does not link to any globl extension.

class MyPrepareTask extends AbstractGemPrepareTask {
    @Inject
    MyPrepareTask(WorkerExecutor we) {
        super(we)
        this.jruby = extensions.create(JRubyExtension.NAME, JRubyExtension, this, 'jrubyx') (1)
        setJrubyJarProvider(project.provider { -> (2)
            GemUtils.findJRubyJar(jruby.jrubyConfiguration, jruby.jrubyVersion) (3)
        })
    }
    private final JRubyExtension jruby
}
1 Create an extension that attaches to the current task and pass the owner task (this) to bind the two together. Also give the associated configuration a special name. (This example uses jrubyx). This is recommended, so that it does not clash with any other condigurations that were created by JRubyExtension instances from other plugins.
2 Set up a provider to resolve the JAR location when needed. This provider is only called by AbstractJRubyPrepare when executing the task actions.
3 GemUtils.findJRubyJar is a utility that resolve the location.

Controlling the cache size

Any task derived from AbstractGemPrepareTask will only cache the task outputs if the size of the files < 3MB. This size can be configured by setting a Gradle or system property called org.ysb33r.gradle.jruby.api.tasks.gem.cache.limit.mb.