Get to Know Grails

grails

An Introduction to the Grails Framework

Søren Berg Glasius

whoami

Søren Berg Glasius

  • Java developer since y2k

  • Groovy & Grails developer since y2k+9

  • OCI Grails Team Member

  • GR8Conf co-founder and organizer

  • Nerd By Nature

Object Computing

  • Groovy And Grails Project Work

  • Grails 2 → 3 Plugin Migrations

  • Grails Plugin Development

  • Grails Core Development

Object Computing

We are hiring!

oci home to grails

Session Agenda

  • Grails

    • Whats in the box?

    • The stack

    • How does it work?

  • Demo!

  • Q/A

This talk is not

  • a deep dive into Grails

Grails

grails

Introduction

What is Grails?

Grails is a powerful web framework, for the Java platform aimed at multiplying developers’ productivity thanks to a Convention-over-Configuration, sensible defaults and opinionated APIs.

It integrates smoothly with the JVM, allowing you to be immediately productive whilst providing powerful features including integrated ORM, Domain-Specific Languages, runtime and compile-time meta-programming and Asynchronous programming.

What’s in the "Box"? (1/3)

  • A Object Relational Mapping (ORM) called GORM

    • simplifies Hibernate

    • partly DB agnostic

    • provides NoSQL access

  • A controller layer built on Spring MVC

What’s in the "Box"? (2/3)

  • Groovy Server Pages view technology (GSP’s)

  • An embedded Tomcat container

  • On the fly reloading when artifacts changes

  • Spring dependency injection

  • Internationalization support (i18n)

What’s in the "Box"? (3/3)

  • A transactional service layer

  • Easy TagLib creation

  • A well defined plugin structure

  • A command line tool

  • Build-system based on Gradle

The Grails Stack

jvm

The Grails Stack

jvm java

The Grails Stack

jvm java jdk

The Grails Stack

jvm java jdk spring

The Grails Stack

jvm java jdk spring hibernate

The Grails Stack

jvm java jdk spring hibernate sitemesh

The Grails Stack

jvm java jdk spring hibernate sitemesh groovy

The Grails Stack

jvm java jdk spring hibernate sitemesh groovy grails
groovy

Groovy

Groovy adj. (or, less commonly, "Groovie" or "Groovey") It is roughly synonymous with words such as "cool", "excellent", "fashionable" or "amazing," depending on context.

 — Wikipedia

Groovy

Groovy adj. (or, less commonly, "Groovie" or "Groovey") It is roughly synonymous with words such as "cool", "excellent", "fashionable" or "amazing," depending on context.

 — Wikipedia

Groovy-Lang

Groovy is a powerful, optionally typed and dynamic language, with static typing and static compilation capabilities, for the Java platform aimed at multiplying developers’ productivity thanks to a concise, familiar and easy to learn syntax.

It integrates smoothly with any Java program, and immediately delivers to your application powerful features, including scripting capabilities, Domain-Specific Language authoring, runtime and compile-time meta-programming and functional programming.

www.groovy-lang.org

The principals in Grails

DRY

Don’t Repeat Yourself

Convention over Configuration

Grails is opinionated.

Sensible Defaults

Keeping config to a minimum.

Getting started

Installing Grails (1/2)

  • Have a Java 8 JDK installed

  • Download Grails (www.grails.org/downloads)

  • Unzip archive

Installing Grails (2/2)

sdkman

Grails: The command line

$ grails
| Enter a command name to run. Use TAB for completion:
grails> _ ->|
create-app       create-plugin    create-profile   gradle           help             list-profiles    open
profile-info
grails> _

Grails: The command line

$ grails
| Enter a command name to run. Use TAB for completion:
grails> list-profiles_
| Available Profiles
--------------------
* angular - A profile for creating applications using AngularJS
* rest-api - Profile for REST API applications
* base - The base profile extended by other profiles
* angular2 - A profile for creating Grails applications with Angular 2
* plugin - Profile for plugins designed to work across all profiles
* profile - A profile for creating new Grails profiles
* react - A profile for creating Grails applications with a React frontend
* rest-api-plugin - Profile for REST API plugins
* web - Profile for Web applications
* web-plugin - Profile for Plugins designed for Web applications
* webpack - A profile for creating applications with node-based frontends using webpack
grails> _

Grails: The command line

$ grails
| Enter a command name to run. Use TAB for completion:
grails> create-app_ ->|

Grails: Our first project

.
├── build.gradle
├── gradle (wrapper)
├── gradle.properties
├── grails-app
│   ├── assets (images, stylesheets, javascript)
│   ├── conf
│   │   └── spring
│   │       └── resources.groovy
│   ├── controllers
│   │   └── UrlMappings.groovy
│   ├── domain
│   ├── i18n (Internationalization)
│   ├── init
│   │   ├── BootStrap.groovy
│   │   └── grails
│   │       └── demo
│   │           └── Application.groovy
│   ├── services
│   ├── taglib
│   ├── utils
│   └── views
│       ├── error.gsp
│       ├── index.gsp
│       ├── layouts
│       │   └── main.gsp
│       └── notFound.gsp
├── src
│   ├── integration-test
│   │   └── groovy
│   ├── main
│   │   ├── groovy
│   │   └── webapp
│   └── test
│       └── groovy

Demo Time

grails

What the Demo Covers: (1/2)

  • Controllers

  • Views

  • Services

  • Domain Objects

What the Demo Covers: (2/2)

  • Scaffolding

  • I18n

  • Sensible defaults

  • Tag-libraries

  • Plugins

Code on GitHub

Summary

Grails

  • Opinionated

  • DRY: Don’t Repeat Yourself

  • Focus on business logic, Grails handles the rest

  • Deploys as a regular WAR file

  • Builds on Spring, Hibernate and Sitemesh

  • Highly extensible plugin structure

  • Write less, do more

Questions

and answers?

Thank You.

Thank You.