Ratpack assemble/package guide

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Ratpack assemble/package guide

LosPejos
Hi!
I want to create a standalone Ratpack application. How can I do this using Gradle? Could you please provide some sample scripts or project.
I assume I have *.jar files, at least one among them contains start class, optionally with some starter script (bat/sh).
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

johnrengelman
Hi -
The necessary steps are documented in the Ratpack Manual

The specific sections you will want to look at:
http://ratpack.io/manual/current/gradle.html#the_application_plugin
http://ratpack.io/manual/current/gradle.html#the_shadow_plugin
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

LosPejos
Thanks for your such a quick response, this is really amazing :-)
Actually, documentation is a little confusing, at least for me.
I've created file build.gradle, copypasted from documentation:

buildscript {
  repositories {
    jcenter()
    maven { url "http://oss.jfrog.org/artifactory/repo" }
  }
  dependencies {
    classpath "io.ratpack:ratpack-gradle:0.9.7-SNAPSHOT"
    classpath 'com.github.jengelman.gradle.plugins:shadow:1.0.2'
  }
}

apply plugin: 'com.github.johnrengelman.shadow'


But when running, I get an error:
FAILURE: Build failed with an exception.                                                                                                                          
                                                                                                                                                                 
* What went wrong:                                                                                                                                                
Task 'runShadow' not found in root project 'ratpack-ws-emu'.                                                                                                      
                                                                                                                                                                 
* Try:                                                                                                                                                            
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
                                                                                                                                                                 
BUILD FAILED                                                                                                                                                      

I'm not so familiar with this new stuff (Gradle I mean), so if it not too complicated for you, could you please point me for a script example, project sceleton or something like this.

Additionally, I'm confusing where to put my Ratpack groovy source: under  /src/main/groovy/ratpack  or under /src/ratpack?


Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

danhyun
To see a list of Gradle tasks you can invoke  `./gradlew tasks`

I believe the task you are looking for is `shadowJar` instead of `shadowRun` as specified in the link John provided.

Secondly you'll probably want to apply the `ratpack-groovy` plugin to get nicer IDE support also specified in the same section in the link http://ratpack.io/manual/current/gradle.html#the_shadow_plugin
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

johnrengelman
In reply to this post by LosPejos
Lazybones is a good tool for creating project skeletons and you can read about it here: http://ratpack.io/manual/current/quick-start.html#using_lazybones_project_templates

We publish a lazy bones template as part of our release process.
Your example above is using a very old version of Ratpack. Is this intentional? You are using 0.9.7-SNAPSHOT. The latest release is 0.9.17 and if you are just getting started with Ratpack, you should be using this release as it's API is becoming more stable as we drive towards a 1.0 release.

We also keep a collection of example projects that you can reference.
This is a good place for you to start: https://github.com/ratpack/example-books/blob/master/build.gradle
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

LosPejos
Wow, guys, you're have a lightning speed answers :-)
According your suggestions, I finished with shadowJar, have a fat jar (about21 MB).
Am I right supposing I have to call my ratpack script "GroovyRatpackMain" as I see in MANIFEST.MF inside a jar:
Main-Class: ratpack.groovy.GroovyRatpackMain
?

Question is, where it should be placed:
/src/main/groovy/???/GroovyRatpackMain.groovy
/src/ratpack/ratpack.groovy (I suppose this is correct?)
Please clarify.
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

LosPejos
Well, I moved my script to /src/ratpack/ratpack.groovy, built my fatjar.
Running java -jar ./myfat.jar
Getting error:
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ivy/core/report/ResolveReport
        at java.lang.Class.getDeclaredMethods0(Native Method)
... <stacktrace skipped>

I suppose this is due to my script grab / grape usage:

@Grapes([
        @Grab('io.ratpack:ratpack-groovy:0.9.17'),
        @Grab(group='org.slf4j', module='slf4j-api', version='1.7.12'),
        @Grab(group='ch.qos.logback', module='logback-core', version='1.1.3'),
        @Grab(group='ch.qos.logback', module='logback-classic', version='1.1.3')
])

How can I get this thing running? Should I manually download some kind of ivy.jar (and its dependencies) and add to a fatjar?
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

johnrengelman
`GroovyRatpackMain` is a framework class we supply. It's the entry point that loads your `ratpack.groovy` file.

`src/ratpack/ratpack.groovy` is the correct location.

You don't need to include any Grape configuration in your `ratpack.groovy` file. This is what Gradle will do. The fatjar will have all the bundled classes inside it.
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

LosPejos
Thank you very much!
I succeeded building fatjar and running it!
Guys you're awesome! )

For benefit of others:
- don't mix builders: if you're using Gradle, remove any Grapes/Grabs from your groovy files and move dependencies to a build.gradle (f.e.)
- put your source code to /src/ratpack/ratpack.groovy
- use last version of ratpack
- use shadowJar to build fat-jar to run it anywhere with java -jar
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack assemble/package guide

Koke
Right!!! Your recommendation to not mixing builders took me home. Thanx a lot.