Skip to content

Commit 6fea898

Browse files
authored
Merge pull request #365 from ysb33r/rubygem-api
Improve GEM handling and resolving (#364, #366, #370)
2 parents d71f514 + 207113a commit 6fea898

File tree

81 files changed

+4002
-2301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+4002
-2301
lines changed

README.adoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ NOTE: JRuby/Gradle 2.0 relies on JRuby 9.x and later.
2323

2424
This repository contains the:
2525

26-
* `base` (in `jruby-gradle-base-plugin/`): dependency resolution, executing Ruby, etc.
27-
* `jar` (in `jruby-gradle-jar-plugin/`): packaging JRuby-based `.jar` files
28-
* `war` (in `jruby-gradle-war-plugin/`): packaging JRuby-based `.war` files
26+
* `core` (in `core-plugin/`): Rubygems proxy.
27+
* `base` (in `base-plugin/`): dependency resolution, executing Ruby, etc.
28+
* `jar` (in `jar-plugin/`): packaging JRuby-based `.jar` files
29+
* `war` (in `war-plugin/`): packaging JRuby-based `.war` files
2930
3031
3132
NOTE: More documentation can be found on link:http://jruby-gradle.org[jruby-gradle.org]

base-plugin/README.adoc

Lines changed: 112 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,16 @@ image::https://api.bintray.com/packages/jruby-gradle/plugins/jruby-gradle-plugin
77

88
=== Compatibility
99

10-
This plugin requires link:http://gradle.org[Gradle] 2.0 or better
11-
10+
This plugin requires link:http://gradle.org[Gradle] 4.0 or better
1211

1312
=== Installing
1413

1514
.build.gradle
1615
[source, groovy]
1716
----
18-
buildscript {
19-
repositories { jcenter() }
20-
21-
dependencies {
22-
/* check jruby-gradle.org for the latest release */
23-
classpath "com.github.jruby-gradle:jruby-gradle-plugin:[1.1.4,2.0)"
24-
}
17+
plugins {
18+
id 'com.github.jruby-gradle.base' version 'VERSION-OF-PLUGIN'
2519
}
26-
27-
apply plugin: 'com.github.jruby-gradle.base'
2820
----
2921

3022
=== Adding gems
@@ -44,15 +36,9 @@ dependencies {
4436
}
4537
----
4638

47-
IMPORTANT: Prereleased gems can only be a specific version due to limitations of mapping a rubygems repository to a maven repository.
39+
IMPORTANT: Prereleased gems should only be a specific version due to limitations of mapping a rubygems repository to an Ivy repository.
4840

49-
NOTE: This functionality currently relies on a deployed version of the
50-
link:https://github.com/torquebox/rubygems-servlets[rubygems-servlets]
51-
software to help proxy a Rubygem repository into a Maven repository format.
52-
This ensures that Gradle can resolve gem-based dependencies. _Currently_ the
53-
plugin release on link:http://rubygems.lasagna.io/proxy/maven/releases[a
54-
Rubygems Maven proxy] operated by link:https://github.com/rtyler[R. Tyler
55-
Croy]
41+
NOTE: This functionality relies on an internal proxy which converts information from https://rubygems.org in to an Ivy repository service. this functionality is enabled by adding `ruby.gems()` to the `repositories` block. If you have a running Maven GEMs proxy you may use that too.
5642

5743
== Tasks
5844

@@ -89,16 +75,7 @@ Common methods for `JRubyExec` for executing a script
8975
* `standardOutput` - `OutputStream`. Capture the output of the script.
9076
* `errorOutput` - `OutputStream`. Capture the error output of the script.
9177
* `ignoreExitValue` - `Boolean`. Ignore the JVm exit value. Exit values are only effective if the exit value of the Ruby script is correctly communicated back to the JVM.
92-
* `configuration` - `String`. Configuration to copy gems from. (*)
93-
* `classpath` - `List`. Additional Jars/Directories to place on classpath.
94-
* `jrubyVersion` - `String`. JRuby version to use if not the same as ```project.jruby.execVersion```.
95-
* `gemWorkDir` - `File`. Provide a custom working directory for unpacking GEMs. By default each `JRubyExec` task
96-
uses it's own work directory. Use this to set a common work directory for a number of tasks.
97-
98-
(*) If `jrubyVersion` has not been set, `jrubyExec` will used as configuration.
99-
However, if `jrubyVersion` has been set, a configuration must also be provded
100-
to maintain dependency isolation, see
101-
link:http://jruby-gradle.org/errors/jrubyexec-version-conflict/[this page] for more details.
78+
* `jruby` - `JRubyPluginExtension`. Allows to override settigns from the global `jruby` extension.
10279

10380
Additional `JRubyExec` methods for controlling the JVM instance
10481

@@ -135,11 +112,8 @@ task needSomeRubyLove {
135112

136113
The behaviour of `project.jrubyexec` is slightly different to that of `JRubyExec`.
137114

138-
* The version of `jruby-complete` is strictly tied to the `jruby.execVersion`. Therefore trying to set `jrubyVersion`
139-
in the ```jrubyexec``` closure will cause a failure
140-
* GEMs and additional JARs are only taken from the `jrubyExec` configuration.
141-
* It is not possible to supply a `configuration` parameter to the `jrubyexec` closure.
142-
* GEMs will be installed to `jruby.gemInstallDir`. Existing gems will not be overwritten.
115+
* The version of JRuby is strictly tied to the global `jruby.jrubyVersion`.
116+
* GEMs and additional JARs are only taken from the `jruby.gemConfiguration` configuration.
143117

144118
As with `JRubyExec`, `args`, `setArgs` and `main` are illegal within the `jrubyexec` closure.
145119
All other methods should work.
@@ -180,7 +154,11 @@ ext {
180154

181155
link:/groovydoc/jruby-gradle-base-plugin/com/github/jrubygradle/JRubyPrepare.html[API docs]
182156

183-
Unpacking occurs using the default `jruby` version as set by `jruby.execVersion`.
157+
Unpacking occurs using the default JRuby version as set by `jruby.jrubyVersion`. This can be overridden within the task itself if required.
158+
159+
In most cases you do not have to do anything. The JRubyPrepare task will be created for you and associated with the appropriate configuration. If you customise configurations or use different configurations for different tasks, Gradle will useually create appropriate `JRubyPrepare` tasks for you and link the appropriate task dependencies.
160+
161+
You can also create your own custom `JRubyPrepare` tasks if required.
184162

185163
.build.gradle
186164
[source,gradle]
@@ -204,11 +182,9 @@ task unpackMyGems(type : JRubyPrepare) {
204182

205183
=== Using the built-in Gem proxy
206184

207-
As of version 1.1.0, the JRuby/Gradle base plugin supports embedding a
208-
link:https://github.com/torquebox/rubygems-servlets[rubygems-servlets] process
209-
*inside* the Gradle process itself. This obviates the need for a third-party
185+
As of version 2.0, the JRuby/Gradle base plugin supports embedding a lightweight proxy inside* the Gradle process itself. This obviates the need for a third-party
210186
proxy to present the Maven-compatible dependency information that JRuby/Gradle
211-
relies on.
187+
relies on and it also supercedes the older link:https://github.com/torquebox/rubygems-servlets[rubygems-servlets] process
212188

213189
.build.gradle
214190
[source,gradle]
@@ -220,43 +196,26 @@ jruby.defaultRepositories false
220196
221197
repositories {
222198
jcenter()
223-
rubygems('https://rubygems.org')
199+
ruby.gems() // <1>
200+
ruby.gems('https://your-own-server.org') // <2>
201+
ruby.gems('https://another-server.org', 'acmegems') // <3>
202+
ruby.torquebox() // <4>
224203
}
225204
226205
dependencies {
227-
gems 'rubygems:sinatra:1.4.5'
206+
gems 'rubygems:sinatra:1.4.5' // <5>
207+
gems 'acmegems:some-gem:1.2.3' // <6>
228208
}
229209
----
210+
<1> Retrieve GEMs from https://rubygems.org
211+
<2> Retrieve GEMs from another server.
212+
<3> Retrieve GEMS from another server and associated a custom group name with that server.
213+
<4> Enabled the legacy Torquebox Maven proxy. Please note that this proxy server is unmaintained upstream and may lead to brittle builds in some cases.
214+
<5> Retrieve a GEM. `rubygems` is the default group for GEMs.
215+
<6> Retrieve a GEM using a custom group.
230216

231-
=== Using a custom Gem repository
232-
233-
By default the jruby plugin will use
234-
link:http://rubygems.lasanga.io[rubygems.lasanga.io] as its source of Ruby
235-
gems. This is a server operated by link:https://github.com/rtyler[R. Tyler
236-
Croy] and it presents a Maven repository of the data from
237-
link:https://rubygems.org[rubygems.org].
238-
239-
If you **do not** wish to use this repository, you can run your own Maven proxy
240-
repository for either rubygems.org or your own gem repository by running the
241-
link:https://github.com/torquebox/rubygems-servlets[rubygems-servlets] server.
242-
243-
You can then use that custom Gem repository with:
244-
245-
.build.gradle
246-
[source,gradle]
247-
----
248-
jruby {
249-
defaultRepositories false
250-
}
251-
252-
repositories {
253-
maven { url 'http://localhost:8989/releases' }
254-
}
255-
256-
dependencies {
257-
gems 'rubygems:my-custom-gem:1.0.1'
258-
}
259-
----
217+
NOTE: If the version of Gradle supports the `content` DSL keyword for repositories, only
218+
requests dependencies with the specific groups will be sent to the GEM repositories.
260219

261220
=== Using the JRuby/Gradle without Gradle
262221

@@ -277,3 +236,86 @@ end
277236

278237
NOTE: The `.rb` file is assuming it's in the top level of the source tree, i.e.
279238
where `build.gradle` is located
239+
240+
== Upgrading to 2.x from 1.7.x
241+
242+
If you are already using the base proxy for work, upgrading will yield a number of surprises. Hopefully they will come as nice wow factors once you have changed your build file.
243+
244+
=== Default repositories
245+
246+
Repositories are no longer added by default. You should explictly declare which repositories you require. If you still need the old behaviour, you can obtain that by
247+
248+
[source,groovy]
249+
----
250+
jruby {
251+
defaultRepositories = true // <1>
252+
}
253+
----
254+
<1> Adds `ruby.gems()` and `jcenter()`.
255+
256+
This functionality is deprecated and will be removed in a future version.
257+
258+
=== jrubyExec configuration
259+
260+
The `jrubyExec` configuration is no longer added as the GEM configuration handling has been cleaned up and much improved in 2.x. If you have a number of instances relying on `jrubyExec` you can do
261+
262+
[source,groovy]
263+
----
264+
configurations {
265+
jrubyExec
266+
}
267+
----
268+
269+
and then enable this configuration either globally as your GEM configuration by doing
270+
271+
[source,groovy]
272+
----
273+
jruby {
274+
gemConfiguration 'jrubyExec'
275+
}
276+
----
277+
278+
or on a task-specific basis
279+
280+
[source,groovy]
281+
----
282+
task myRunner(type: JRubyExec) {
283+
jruby {
284+
gemConfiguration 'jrubyExec' // <1>
285+
}
286+
}
287+
----
288+
<1> Enables configuration only for the given task.
289+
290+
NOTE: If you set `gemConfiguration 'jrubyExec'` you will also notice that Gradle creates a `jrubyPrepareJrubyExec` tasks to unpack your GEMs in an isolated area.
291+
292+
=== Setting GEM & JAR installation directories
293+
294+
This behaviour was already deprecated in 1.7.x and has now been removed. Directories are now associated with specific configuration names. For the `gems` configuration this is in `${buildDir}/.gems`. For other configurations it will be a different directory. You can obtain the directory, via the `JRubyPrepare.getOutputDir()` method.
295+
296+
=== Setting the JRuby version to use
297+
298+
`jruby.defaultVersion` is deprecated. Do this rather via
299+
300+
[source,groovy]
301+
----
302+
jruby {
303+
jrubyVersion = '9.1.2.3'
304+
}
305+
----
306+
307+
You can also override the JRuby version a per-task basis.
308+
309+
[source,groovy]
310+
----
311+
task myRunner(type: JRubyExec) {
312+
jruby {
313+
jrubyVersion = '9.1.2.3' // <1>
314+
}
315+
}
316+
----
317+
<1> Use a different version of JRuby only in a specific task, whilst using a globally configured version for everything else.
318+
319+
=== Changing the JRubyExec configuration
320+
321+
The `configuration` is deprecated. Use `jruby.gemConfiguration` on the task itself for a custom configuration.

base-plugin/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ ext {
2929

3030
dependencies {
3131

32-
compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
33-
compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
32+
compile project(':jruby-gradle-core-plugin')
3433
runtime('de.saumya.mojo:rubygems:0.2.3@war') {
3534
// we just want the war file on the classloader for the application
3635
// to find it and use the war-file from filesystem
@@ -41,10 +40,12 @@ dependencies {
4140

4241
testCompile(spockVersion) {
4342
exclude module: 'groovy-all'
43+
exclude group: 'org.codehaus.groovy'
4444
}
4545

4646
integrationTestCompile(spockVersion) {
4747
exclude module: 'groovy-all'
48+
exclude group: 'org.codehaus.groovy'
4849
}
4950

5051
// NOTE: This is used by JRubyPrepareGemsIntegrationSpec

base-plugin/src/gradleTest/jrubyExec/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import com.github.jrubygradle.JRubyExec
22

33
apply plugin : 'com.github.jruby-gradle.base'
44

5+
configurations {
6+
jrubyExec
7+
}
8+
59
dependencies {
610
jrubyExec ':credit_card_validator:1.1.0@gem'
711
}
812

9-
jruby {
10-
defaultRepositories = false
11-
}
1213

1314
task requiresGems( type : JRubyExec ) {
15+
jruby {
16+
gemConfiguration 'jrubyExec'
17+
}
18+
1419
script 'scripts/requiresGem.rb'
1520
}
1621

base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyExecExtensionIntegrationSpec.groovy

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
5454

5555
void "Running a script that requires a jar"() {
5656
setup:
57-
def leadingDir = 'jrubyExec/jars/org/bouncycastle/'
57+
def leadingDir = '.gems/jars/org/bouncycastle/'
5858
def artifactPath = "${BCPROV_NAME}/${bcprovVer}/${BCPROV_NAME}-${bcprovVer}"
5959
def withPattern = ~/.*\["file:.+${leadingDir}${artifactPath}\.jar"\].*/
6060

@@ -86,24 +86,6 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
8686
result.output =~ /Not valid/
8787
}
8888

89-
void "Running a script that requires a gem, a separate jRuby, a separate configuration and a custom gemWorkDir"() {
90-
setup:
91-
final String customGemDir = 'customGemDir'
92-
useScript(REQUIRES_GEM)
93-
createJRubyExecProject withCreditCardValidator(), """
94-
script '${REQUIRES_GEM}'
95-
jrubyArgs '-T1'
96-
gemWorkDir { new File(project.buildDir, '${customGemDir}' ) }
97-
"""
98-
99-
when:
100-
BuildResult result = build()
101-
102-
then:
103-
result.output =~ /Not valid/
104-
new File(projectDir, "build/${customGemDir}").exists()
105-
}
106-
10789
void "Running a script that requires environment variables"() {
10890
// This tests that the passthrough invocation
10991
// happens for overloaded versions of environment
@@ -131,7 +113,7 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
131113
}
132114

133115
private BuildResult build() {
134-
gradleRunner(DEFAULT_TASK_NAME, '-i').build()
116+
gradleRunner(DEFAULT_TASK_NAME, '-i', '-s').build()
135117
}
136118

137119
@SuppressWarnings('BuilderMethodWithSideEffects')
@@ -152,14 +134,16 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
152134
${jrubyexecConfig}
153135
}
154136
}
137+
138+
dependsOn jrubyPrepare
155139
}
156140
"""
157141
}
158142

159143
private String withJarToUse(String jarFormat) {
160144
"""
161145
dependencies {
162-
jrubyExec ${jarFormat}
146+
gems ${jarFormat}
163147
}
164148
"""
165149
}
@@ -171,4 +155,4 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
171155
private String getBcprovVer() {
172156
testProperties.bcprovVersion
173157
}
174-
}
158+
}

0 commit comments

Comments
 (0)