From MelbJVM July 2014
This presentation covers building single page web applications with Gradle, including why we chose to use Gradle instead of a more commonly used JS based build tool, and the benefits by integrating a JS webapp into the JVM environment.
5. Our App
Single page app
Choose reports to run, filter by an order or client
Query the endpoint, Google BigQuery Datastore
with language specific APIs for Java + JavaScript
Return interactive charts
10. The PoC that Grew
Proof of Concept Successful
At this stage a couple of monolithic JS files held
together by a static html page
Time to think about some proper JS tooling
12. To market, to market, to become a JS-
Hipster
Set proxy
$ npm config set https-
proxy="https://NTLMREALMuser:pword@proxy.corp.com:8080/"
$ npm config set
proxy=“http://NTLMREALMuser:pword@proxy.corp.com:8080/"
Run Npm…
$ npm install npm
npm http GET https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm
… Looks Promising…
13. Victory Snatched by the Jaws of
Defeat
But alas, our clients site hit a problem
npm ERR! Error: tunneling socket could not be
established,
cause=140230033848128:error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown
protocol:../deps/openssl/openssl/ssl/s23_clnt.c:766:
14. SSL23_GET_SERVER_HELLO:unkno
wn protocol
Stack overflow features many casualties across all
kinds of staple unix tools that use HTTPS
Solutions say configure tool or proxy to not verify
SSL (you like man in the middle vulnerabilities?)
In corporate IT at client site we can’t & wont do
this.
15. So much for being a hipster
Image Source Photobucket
16. JS - Climbing the
development tools
tree,
Taking each branch on the fall down
26. If something doesn't work take a look at issues and
pull requests in Github
Support
27. Gradle Tasks
Build tasks
-----------
combineCss - Combine many CSS files into one
combineJs - Combine many JavaScript files into one
gzipCss - GZip a given CSS file
gzipJs - GZip a given JavaScript file
lesscss - Compiles LESS files into CSS
minifyCss - Minify CSS using YUI Minifier
minifyJs - Minify JavaScript using Closure Compiler
props2js - Convert Java properties files for use with
JavaScript
requireJs - Run the r.js Optimizer to produce Require.js
output
28. Ok we are setup, now what?
Combination,
Minification
GZipping
34. CSS
// Declare your sources
css.source {
dev {
css {
srcDir "app/styles"
include "*.css"
exclude "*.min.css"
}
}
}
35. CSS
// Specify a collection of files to be combined, then
minified and finally GZip compressed.
combineCss {
source = css.source.dev.css.files
dest = "${buildDir}/all.css"
}
48. Closure Compiler Options
A bit hard to find them all. You can find them in a
source file in the Closure compiler project.
https://github.com/google/closure-
compiler/blob/master/src/com/google/javascript/jsc
omp/CompilerOptions.java
49. defineReplacements
// config.js
/**
* Flag to indicate console and extra logging
throughout the app
* @define {boolean} allow the value of this bool to be
* overwritten at closure compiler / minification
time
* @const
* @type {boolean}
*/
var MY_DBUG_FLAG = true;
68. Remember!
Gradle works for building HTML/ JS / CSS assets
Embedded Server from Checkout
End 2 End Visibility
Proxies
69. Thanks
Blog goes into more detail
http://blog.shinetech.com/2014/03/19/javascript-webapps-
with-gradle/
Photos
Tom Botton - MelbJVM September
Brigitte Schuckert - Gradleware Keynote
Kon Soulianidis - Pisa & Monkey looking in lens
Climbing the Tree - Mary Evans. Licensed
Shipping Containers - Jim Bahn. Flickr. CC License
Animated Gifs - Photobucket
Duke, Grunt, Gradle logos, respective owners
Notes de l'éditeur
Initially app was only JavaScript client talking directly to the datasource. Users auth’d with BigQuery directly
So people usually ask when I tell them we used Gradle to make a single page web app , why not Grunt or Gulp, or whatever else is fancy and in vogue?
Dream of being a JS hipster aka Instant Gratification Monkey
Now the chance to learn all the cool stuff
Angular
Grunt
Bower
I took this picture from a site
There is a project called JHipster that combines Maven, Grunt & Spring MVC, AngularJS with Yeoman. A few weeks ago it had a minor release that added Gradle support.
JHipster is a Yeoman generator, used to create a Maven + Spring + AngularJS project, with full hot reload of Java and JavaScript code.
Yeoman needs npm, so does grunt so still a fail for us. But going in the right direction.
JavaScript has been climbing the tree of software development tools, then reaching the top and falling, taking every branch on the tree down.
So far we’ve just got some cookie cutter setup for the first version
You can see pretty simply, the html, js and css driving the show
But we’ve got this libs folder…
Our dependencies bring in their own things into the mix.
Bootstrap has 3 resources folders, css, js and fonts directories
Holder and Jquery bring in their js libs.
Most libraries provide both minified and regular versions of their libs
Some have map files that we may want to deploy with the minified versions so we can debug in chrome/firefox
And just for the fun of it, bootstrap decides to include fonts
And this build.gradle file just seems out of place in the web folder
GASP SHOCK HORROR! Find Sound Effects and Clip art (eg 1950’s woman with hands around mouth). Sound effects of screams, shrieks
In todays talk we’ll build from the ground up an application to interact with a RESTful API
To start with, we’ll use Twitter Bootstrap’s dashboard theme
For learning Gradle using another language is a great experience
For learning Gradle using another language is a great experience
For learning Gradle using another language is a great experience