Skip to content

Commit 5989e72

Browse files
author
R. Tyler Croy
committed
Merge pull request #51 from ysb33r/master
Support in 'base' for warbler-bootstrap so that derived plugins can make use of it.
2 parents 33914ca + c7e0ef1 commit 5989e72

File tree

5 files changed

+161
-157
lines changed

5 files changed

+161
-157
lines changed

README.md

Lines changed: 98 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,38 @@ The Ruby gem dependency code for this project relies on the [Rubygems Maven
1212
proxy](http://rubygems-proxy.torquebox.org/) provided by the
1313
[Torquebox](http://torquebox.org) project.
1414

15-
## Compatilibity
16-
17-
This plugin requires Gradle 2.0 or better
18-
19-
## Getting Started
20-
21-
### Setting up Gradle
15+
This is the base plugin. If you are interesting in doing the following then consult the pages for the appropriate
16+
plugins:
2217

23-
**Note:** This assumes you already have [Gradle](http://gradle.org) installed.
18+
* Building JRuby-based Java JARs, including making them executable -
19+
[jruby-gradle-jar-plugin](http://github.come/jruby-gradle/jruby-gradle-jar-plugin)
20+
* Building JRuby-based Java Web Applications (WARs), -
21+
[jruby-gradle-war-plugin](http://github.come/jruby-gradle/jruby-gradle-war-plugin)
2422

25-
```bash
26-
% mkdir fancy-webapp
27-
% cd fancy-webapp
28-
% git init
29-
Initialized empty Git repository in /usr/home/tyler/source/github/fancy-webapp/.git/
30-
% gradle wrapper # Create the wrappers to easily bootstrap others
31-
wrapper
3223

33-
BUILD SUCCESSFUL
34-
35-
Total time: 6.411 secs
36-
% git add gradle gradlew gradlew.bat
37-
% git commit -m "Initial commit with gradle wrappers"
38-
```
24+
## Compatilibity
3925

40-
### Creating a gradle configuration file
26+
This plugin requires Gradle 2.0 or better
4127

42-
Create a `build.gradle` file in the root of `fancy-webapp/` with the following:
28+
`JRuby 1.7.14` seem to have some bugs. Although this plugin has a workaround for this version it is recommended that you
29+
avoid using `1.7.14` with the `jruby-gradle-plugin`.
4330

31+
## Getting Started
4432

4533
```groovy
46-
apply plugin: 'com.lookout.jruby'
47-
4834
buildscript {
4935
repositories { jcenter() }
5036
5137
dependencies {
52-
classpath group: 'com.lookout', name: 'jruby-gradle-plugin', version: '2.1.+'
38+
classpath group: 'com.github.jrubygradle', name: 'jruby-gradle-plugin', version: '0.1.2'
5339
}
5440
}
41+
42+
apply plugin: 'com.github.jrubygradle.base'
5543
```
5644

45+
### Adding gems
46+
5747
You can also add Ruby gem dependencies in your `build.gradle` file under the
5848
`gem` configuration, e.g.:
5949

@@ -64,141 +54,14 @@ dependencies {
6454
}
6555
```
6656

67-
In order to include Java-based dependencies in a `.war` file, declare those
68-
dependencies under the `jrubyWar` configuration, e.g.:
69-
70-
```groovy
71-
dependencies {
72-
jrubyWar group: 'org.apache.kafka', name: 'kafka_2.9.2', version: '0.8.+'
73-
jrubyWar group: 'log4j', name: 'log4j', version: '1.2.+', transitive: true
74-
}
75-
```
76-
77-
Dependencies declared under the `jrubyWar` configuration will be copied into
78-
`.jarcache/` and `.war/WEB-INF/libs` when the archive is created.
79-
80-
8157
## Default Tasks
8258

8359
The plugin provides the following tasks:
8460

85-
* `jrubyWar` - Creates a runnable web archive file in `build/libs` for your
86-
project.
8761
* `jrubyPrepareGems` - Extract GEMs declared as dependencies under `gems` to `jruby.gemInstallDir`. This is as instance
8862
of `JRubyPrepareGems`.
8963
* `jrubyPrepare` - Call `jrubyPrepareGems`. Also copies the
9064
content of Java-based dependencies into `.jarcache/` for interpreted use
91-
(see below)
92-
* `jrubyClean` - Cleans up the temporary directories that tasks like
93-
`jrubyWar`- Creates a `war` file
94-
95-
## Creating a .war
96-
97-
Currently the Gradle tooling expects the web application to reside in
98-
`src/main/webapp/WEB-INF`, so make sure your `config.ru` and application code
99-
are under that root directory. It may be useful to symbolicly link this to
100-
`app/` in your root project directory. An *full* example of this can be found in the
101-
[ruby-gradle-example](https://github.com/rtyler/ruby-gradle-example)
102-
repository.
103-
104-
Once your application is ready, you can create the `.war` by executing the `jrubyWar` task:
105-
106-
```bash
107-
% ./gradlew jrubyWar
108-
:compileJava UP-TO-DATE
109-
:processResources UP-TO-DATE
110-
:classes UP-TO-DATE
111-
:jrubyCacheJars
112-
:jrubyCacheGems
113-
:jrubyPrepareGems
114-
/home/tyler/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/yaml.rb:84:in `<top (required)>':
115-
It seems your ruby installation is missing psych (for YAML output).
116-
To eliminate this warning, please install libyaml and reinstall your ruby.
117-
Successfully installed rack-1.5.2
118-
Successfully installed rack-protection-1.5.3
119-
2 gems installed
120-
/home/tyler/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/yaml.rb:84:in `<top (required)>':
121-
It seems your ruby installation is missing psych (for YAML output).
122-
To eliminate this warning, please install libyaml and reinstall your ruby.
123-
Successfully installed rake-10.3.2
124-
1 gem installed
125-
/home/tyler/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/yaml.rb:84:in `<top (required)>':
126-
It seems your ruby installation is missing psych (for YAML output).
127-
To eliminate this warning, please install libyaml and reinstall your ruby.
128-
Successfully installed tilt-1.4.1
129-
1 gem installed
130-
/home/tyler/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/yaml.rb:84:in `<top (required)>':
131-
It seems your ruby installation is missing psych (for YAML output).
132-
To eliminate this warning, please install libyaml and reinstall your ruby.
133-
Successfully installed sinatra-1.4.5
134-
1 gem installed
135-
:jrubyPrepare
136-
:jrubyWar
137-
138-
BUILD SUCCESSFUL
139-
140-
Total time: 1 mins 34.84 secs
141-
%
142-
```
143-
144-
Once the `.war` has been created you can find it in `build/libs` and deploy that into a servlet container such as Tomcat or Jetty.
145-
146-
147-
## Using the Ruby interpreter
148-
149-
There are still plenty of cases, such as for local development, when you might
150-
not want to create a full `.war` file to run some tests. In order to use the
151-
same gems and `.jar` based dependencies, add the following to the entry point
152-
for your application:
153-
154-
```ruby
155-
# Hack our GEM_HOME to make sure that the `rubygems` support can find our
156-
# unpacked gems in ./vendor/
157-
vendored_gems = File.expand_path(File.dirname(__FILE__) + '/vendor')
158-
if File.exists?(vendored_gems)
159-
ENV['GEM_HOME'] = vendored_gems
160-
end
161-
162-
jar_cache = File.expand_path(File.dirname(__FILE__) + '/.jarcache/')
163-
if File.exists?(jar_cache)
164-
# Under JRuby `require`ing a `.jar` file will result in it being added to the
165-
# classpath for easy importing
166-
Dir["#{jar_cache}/*.jar"].each { |j| require j }
167-
end
168-
```
169-
170-
**Note:** in the example above, the `.rb` file is assuming it's in the top
171-
level of the source tree, i.e. where `build.gradle` is located
172-
173-
## Advanced Usage
174-
175-
### Using a custom Gem repository
176-
177-
By default the jruby plugin will use
178-
[rubygems-proxy.torquebox.org](http://rubygems-proxy.torquebox.org) as its
179-
source of Ruby gems. This is a server operated by the Torquebox project which
180-
presents [rubygems.org](https://rubygems.org) as a Maven repository.
181-
182-
If you **do not** wish to use this repository, you can run your own Maven
183-
proxy repository for either rubygems.org or your own gem repository by
184-
running the [rubygems-servlets](https://github.com/torquebox/rubygems-servlets)
185-
server.
186-
187-
You can then use that custom Gem repository with:
188-
189-
```groovy
190-
jruby {
191-
defaultRepositories = false
192-
}
193-
194-
repositories {
195-
maven { url : 'http://localhost:8989/releases' }
196-
}
197-
198-
dependencies {
199-
gems group: 'com.lookout', name: 'custom-gem', version: '1.0.+'
200-
}
201-
```
20265

20366
## JRubyExec - Task for Executing a Ruby Script
20467

@@ -287,8 +150,89 @@ task unpackMyGems( type : JRubyPrepareGems ) {
287150
outputDir buildDir
288151
289152
// Add one or more gems
290-
// Can be String(s), File(s), FleCollection(s) or Configuration(s)
153+
// Can be String(s), File(s), FileCollection(s) or Configuration(s)
291154
gems project.configuration.gems
292155
293156
}
294157
```
158+
159+
160+
## Advanced Usage
161+
162+
### Using a custom Gem repository
163+
164+
By default the jruby plugin will use
165+
[rubygems-proxy.torquebox.org](http://rubygems-proxy.torquebox.org) as its
166+
source of Ruby gems. This is a server operated by the Torquebox project which
167+
presents [rubygems.org](https://rubygems.org) as a Maven repository.
168+
169+
If you **do not** wish to use this repository, you can run your own Maven
170+
proxy repository for either rubygems.org or your own gem repository by
171+
running the [rubygems-servlets](https://github.com/torquebox/rubygems-servlets)
172+
server.
173+
174+
You can then use that custom Gem repository with:
175+
176+
```groovy
177+
jruby {
178+
defaultRepositories = false
179+
}
180+
181+
repositories {
182+
maven { url : 'http://localhost:8989/releases' }
183+
}
184+
185+
dependencies {
186+
gems group: 'com.lookout', name: 'custom-gem', version: '1.0.+'
187+
}
188+
```
189+
190+
## Using the Ruby interpreter
191+
192+
There are still plenty of cases, such as for local development, when you might
193+
not want to create a full `.war` file to run some tests. In order to use the
194+
same gems and `.jar` based dependencies, add the following to the entry point
195+
for your application:
196+
197+
```ruby
198+
# Hack our GEM_HOME to make sure that the `rubygems` support can find our
199+
# unpacked gems in build/vendor/
200+
vendored_gems = File.expand_path(File.dirname(__FILE__) + '/build/vendor')
201+
if File.exists?(vendored_gems)
202+
ENV['GEM_HOME'] = vendored_gems
203+
end
204+
205+
jar_cache = File.expand_path(File.dirname(__FILE__) + '/.jarcache/')
206+
if File.exists?(jar_cache)
207+
# Under JRuby `require`ing a `.jar` file will result in it being added to the
208+
# classpath for easy importing
209+
Dir["#{jar_cache}/*.jar"].each { |j| require j }
210+
end
211+
```
212+
213+
**Note:** in the example above, the `.rb` file is assuming it's in the top
214+
level of the source tree, i.e. where `build.gradle` is located
215+
216+
217+
## Quickstart for those unfamiliar with Gradle
218+
219+
**Note:** This assumes you already have [Gradle](http://gradle.org) installed. If you are not on Windows it is recommended
220+
that you use [GVM](http://gvmtool.net) to install Gradle
221+
222+
```bash
223+
% mkdir fancy-webapp
224+
% cd fancy-webapp
225+
% git init
226+
Initialized empty Git repository in /usr/home/tyler/source/github/fancy-webapp/.git/
227+
% gradle wrapper init # Create the wrappers to easily bootstrap others
228+
:wrapper
229+
:init
230+
231+
BUILD SUCCESSFUL
232+
233+
Total time: 6.411 secs
234+
% git add gradle gradlew gradlew.bat
235+
% git commit -m "Initial commit with gradle wrappers"
236+
```
237+
238+
Edit the created `build.gradle` file in the root of `fancy-webapp/` as above

src/main/groovy/com/github/jrubygradle/GemUtils.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class GemUtils {
7777

7878
project.logger.info "Installing " + (gemsToProcess.collect { File it -> it.name }).join(',')
7979

80+
81+
8082
project.javaexec {
8183
setEnvironment [:]
8284
main 'org.jruby.Main'
@@ -86,6 +88,12 @@ class GemUtils {
8688
args gem
8789
}
8890
args '--ignore-dependencies', "--install-dir=${destDir.absolutePath}", '-N'
91+
92+
// Workaround for bug
93+
if(jRubyClasspath.name.contains('1.7.14')) {
94+
project.logger.debug "Gem installation: Working around bug in jruby 1.7.14"
95+
environment HOME : project.gradle.gradleUserHomeDir.absolutePath
96+
}
8997
}
9098
}
9199
}

src/main/groovy/com/github/jrubygradle/JRubyPlugin.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class JRubyPlugin implements Plugin<Project> {
3030
}
3131

3232
project.configurations.create(JRubyExec.JRUBYEXEC_CONFIG)
33-
// MOVE: project.configurations.create(JRubyJar.JRUBYJAR_CONFIG)
3433
JRubyExecDelegate.addToProject(project)
3534

3635
// In order for jrubyWar to work we'll need to pull in the warbler
@@ -43,8 +42,6 @@ class JRubyPlugin implements Plugin<Project> {
4342
}
4443
}
4544

46-
47-
4845
JRubyExec.updateJRubyDependencies(project)
4946
}
5047

src/main/groovy/com/github/jrubygradle/JRubyPluginExtension.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ class JRubyPluginExtension {
1919
*/
2020
String execVersion = defaultVersion
2121

22+
/** Setting the warbler bootstrap version that can be used for dependencies
23+
* By default it will use any version 1.0 or better. Setting this property
24+
* allows for locking down the build to one specific version.
25+
*
26+
* @since 0.1.2
27+
*/
28+
@Incubating
29+
String warblerBootstrapVersion = '1.+'
30+
2231
/** Set this to false if you do not want the default set of repositories to be loaded.
2332
*
33+
* @since 0.1.1
2434
*/
2535
@Incubating
2636
boolean defaultRepositories = true

0 commit comments

Comments
 (0)