Skip to content
This repository has been archived by the owner on May 19, 2019. It is now read-only.

WIP create executable jar using jruby-main artifact #38

Merged
merged 1 commit into from
May 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ jruby-gradle-jar-plugin

Plugin for creating JRuby-based java archives

## Breaking Changes

the default init script is now: META-INF/jar-bootstrap.rb

this breaks the old behaviour where the init script was META-INF/init.rb

## Compatibility

Expand Down Expand Up @@ -34,7 +39,6 @@ This loads the following plugins if they are not already loaded:

+ `com.github.jrubygradle.base`
+ `java-base`
+ `com.github.johnrengelman.shadow`

## Using the plugin

Expand Down Expand Up @@ -76,12 +80,6 @@ task myJar (type :Jar) {
If nothing is specified, then the bootstrap will look for a Ruby script `META-INF/jar-bootstrap.rb`.
It is also possible to set the entry script. This must be specified relative to the root of the created JAR.

**NOTE:** There is currently a [known
issue](https://github.com/jruby-gradle/jruby-gradle-jar-plugin/issues/14) with
rebuilding a `shadowJar` when using the `initScript` setting. If you change the
setting, you will need to execute the `clean` task and rebuild for it to take
effect.

```groovy
jrubyJavaBootstrap {
jruby {
Expand All @@ -98,15 +96,10 @@ or another specified script.

**Please note that executable JARs are still an incubating feature**.

Executable JARs are indirectly supported via the [Gradle Shadow Jar plugin](http://plugins.gradle.org/plugin/com.github.johnrengelman.shadow).


### Configuring Shadow JAR

Configuration is exactly the same as for a normal JAR class.
Configuration is needs to declare the main class then the jar will be executable.

```groovy
shadowJar {
jar {
jruby {

// Use the default bootstrap class
Expand All @@ -121,7 +114,3 @@ shadowJar {
}
}
```

See [Shadow JAR README](https://github.com/johnrengelman/shadow/blob/master/README.md) for configuration specifics.
In a similar fashion to the `jar` task, the `shadowJar` task will make use of the `jrubyJavaBootstrap` task to
create and compile a basic bootstrap class.
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ targetCompatibility = '1.6'
repositories {
jcenter()
mavenLocal()
maven { url 'http://dl.bintray.com/rtyler/jruby' }
}

configurations {
Expand All @@ -35,8 +34,7 @@ configurations {
dependencies {
compile gradleApi()
compile localGroovy()
compile 'com.github.jruby-gradle:jruby-gradle-plugin:0.1.11+'
runtime 'com.github.jengelman.gradle.plugins:shadow:1.1.2+'
compile 'com.github.jruby-gradle:jruby-gradle-plugin:0.1.16+'

testCompile ("org.spockframework:spock-core:0.7-groovy-${gradle.gradleVersion.startsWith('1.')?'1.8':'2.0'}") {
exclude module : 'groovy-all'
Expand All @@ -45,15 +43,15 @@ dependencies {
// For the testRepo tests I am locking the versions, instead of a open version, as it makes
// unit testing easier, This does not affect the final artifact.
// If you change values here, you need to update JRubyJarPluginSpec as well.
testRepo ('org.jruby:jruby-complete:1.7.17') {
testRepo ('org.jruby:jruby-complete:1.7.19') {
transitive = false
}
testRepo ('de.saumya.mojo:jruby-mains:0.2.0') {
transitive = false
}
testRepo ("org.spockframework:spock-core:0.7-groovy-2.0") {
transitive = false
}

testRepo 'com.github.jengelman.gradle.plugins:shadow:1.1.2'

}

ext {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the removal of this final closing } ius causing the build to fail in Travis

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import com.github.jrubygradle.GemUtils
/** Helper class to add extra methods to {@code Jar} tasks in order to add JRuby specifics.
*
* @author Schalk W. Cronjé
* @author Christian Meier
*/
class JRubyJarConfigurator {

static final String DEFAULT_BOOTSTRAP_CLASS = 'com.github.jrubygradle.jar.bootstrap.JarMain'
static final String SHADOW_JAR_TASK_CLASS = 'com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar'
static final String DEFAULT_MAIN_CLASS = 'de.saumya.mojo.mains.JarMain'
static final String DEFAULT_EXTRACTING_MAIN_CLASS = 'de.saumya.mojo.mains.ExtractingMain'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of DEFAULT_EXTRACT_MAIN_CLASS ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you read my comment in the meanwhile. sometimes running from inside the jar fails like "rake spec" using RSpec rake task does spawn ruby and this spawning will fail. will see to JRuby itself to fix it on the JRuby if possible. but for the time being we need to offer both cases to cover more applications (hopefully all applications)


// This is used by JRubyJarPlugin to configure Jar classes
@PackageScope
Expand All @@ -24,15 +25,6 @@ class JRubyJarConfigurator {
configure()
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether I am happy with dropping shadowJar support completely. What I do think is to definitely remove it from a fixed dependency in build.gradle. It might still be worthwhile for someone who want to use that instead to go that way bu explicitly including it in their buildscript and applying the plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds fair to treat jar and shadowJar alike. will put it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on second thought: I moved back the shadowJar option for jruby-gradle-jar-plugin BUT things will not really work when you use it since all those embedded jars are gone and jruby-main will look for them and not find them.

@PackageScope
static void afterEvaluateAction( Project project ) {
project.tasks.withType(Jar) { t ->
if(t.class.superclass.name == SHADOW_JAR_TASK_CLASS && t.name=='shadowJar') {
t.configurations.add(project.configurations.getByName('jrubyJar'))
}
}
}

/** Adds a GEM installation directory
*/
void gemDir(def properties=[:],File f) {
Expand All @@ -45,7 +37,20 @@ class JRubyJarConfigurator {
* @param dir Source folder. Will be handled by {@code project.files(dir)}
*/
void gemDir(def properties=[:],Object dir) {
archive.with GemUtils.gemCopySpec(properties,archive.project,dir)
jar().with GemUtils.gemCopySpec(properties,archive.project,dir)
}

/** Adds a GEM installation directory
*/
void jarDir(File f) {
jarDir(f.absolutePath)
}

/** Adds a JAR installation directory
* @param dir Source folder. Will be handled by {@code project.files(dir)}
*/
void jarDir(Object dir) {
jar().with GemUtils.jarCopySpec(archive.project, dir)
}

/** Makes the JAR executable by setting a custom main class
Expand All @@ -54,11 +59,33 @@ class JRubyJarConfigurator {
*/
@Incubating
void mainClass(final String className) {
archive.with {
jar().with {
manifest {
attributes 'Main-Class': className
}
}
jar().with archive.project.copySpec {
from {
archive.project.configurations.jrubyJar.collect {
archive.project.zipTree( it )
}
}
include '**'
exclude 'META-INF/MANIFEST.MF'
// some pom.xml are readonly which creates problems
// with zipTree on second run
exclude 'META-INF/maven/**/pom.xml'
}
}

@Incubating
void initScript(final String scriptName) {
def script = archive.project.file(scriptName)
jar().with archive.project.copySpec {
from(script.parent)
include script.name
rename { 'jar-bootstrap.rb' }
}
}

/** Sets the defaults
Expand All @@ -71,37 +98,46 @@ class JRubyJarConfigurator {
switch(it) {
case 'gems':
case 'mainClass':
case 'extractingMainClass':
"default${it.capitalize()}"()
}
}
}

/** Loads the default GEM installation directory
/** Loads the default GEM installation directory and
* JAR installation directory
*
*/
void defaultGems() {
gemDir({archive.project.jruby.gemInstallDir})
// gems depend on jars so we need to add meaningful default
jarDir({archive.project.jruby.jarInstallDir})
}

/** Makes the executable by adding a default main class
*
*/
@Incubating
void defaultMainClass() {
mainClass(DEFAULT_BOOTSTRAP_CLASS)
mainClass(DEFAULT_MAIN_CLASS)
}

boolean isShadowJar() {
shadowJar
/** Makes the executable by adding a default main class
* which extracts the jar to temporary directory
*
*/
@Incubating
void defaultExtractingMainClass() {
mainClass(DEFAULT_EXTRACTING_MAIN_CLASS)
}

private JRubyJarConfigurator(Jar a) {
archive = a
if (a.class.name == SHADOW_JAR_TASK_CLASS || a.class.superclass.name == SHADOW_JAR_TASK_CLASS) {
shadowJar = true
}
}

private Jar jar() {
return archive.project.tasks.getByName('jrubyJar')
}

private Jar archive
private boolean shadowJar = false
}
Loading