what's new in grails 3

43
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SPRINGONE2GX WASHINGTON, DC What’s new in Grails 3? By Graeme Rocher @graemerocher

Upload: spring-by-pivotal

Post on 16-Apr-2017

2.116 views

Category:

Technology


0 download

TRANSCRIPT

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SPRINGONE2GXWASHINGTON, DC

What’s new in Grails 3?By Graeme Rocher

@graemerocher

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Who we are?

Jeff Scott Brown Object Computing Inc. @jeffscottbrown [email protected]

2

Graeme Rocher Object Computing Inc. @graemerocher [email protected]

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Grails + OCI• OCI focused on Grails• Full service support

– Consulting– Training– Support

• Commitment to engineering • Grails team at OCI growing

– Come speak to us!

3

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 4

More at ociweb.com/grails

Visit the OCI’s Table #2 to meet our Grails Team!

Graeme Rocher Jeff Brown

Dave Klein Colin Harrington

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 5

More at ociweb.com/grails

The OCI Grails Team is growing — will You join us?

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

State of Nation• Grails 3.0.7 the latest version• Grails 3.1 Milestone 1 available• Grails 2.x maintenance mode• Grails 2.x plugins being migrated

• The ones worth migrating

6

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Join the Slack Community!

7

http://slack-signup.grails.org

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

What’s new in Grails 3?• Gradle Build System• Built on Spring Boot• Application Profiles• Plugins via Traits• New Code Generation API• Application Event Model• More - Interceptors, Application class, Geb tests etc.

8

3.03

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Gradle• Grails 2.x build system removed• Replaced with Gradle build• Complete access to Gradle plugin

ecosystem• Powerful and flexible builds• Build related plugins replaced

by Gradle equivalents • (code coverage, findbugs etc.)

9

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Plugin Delineation

10

Grails.sh

Static void m

ain

Gradle B

uild

Forked Grails Runtime

test-app

shellrun-app

console

Codegen Plugins

Build Time Plugins

Runtime Plugins

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Gradle• Allow Micro or Monolith Applications• Multi-Project Plugin Architectures• Run individual sub projects • Or run as a whole

11

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Demo

12

Gradle

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Spring Boot• Grails 3 built on Spring Boot• Boot handles

• Embedded servers• Runnable JARs• WAR packaging• Configuration• Spring Cloud

13

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Why Spring Boot?• Handles Fat JAR and embedding• Already supports different runtimes• Includes monitoring and health

checks• Grails 3 apps can take advantage of

Boot auto configuration• Spring Cloud

14

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Demo

15

Spring Boot

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

The Application Class• Found in grails-app/init • Has a static void main, so can be run / debugged from the IDE• Implements grails.core.GrailsApplicationLifeCycle

• Same hooks available to plugins• Can define beans with doWithSpring or @Bean • Can define packaging scanning with packageNames()

16

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

The Application Class

17

import  grails.boot.GrailsApp  import  grails.boot.config.*  

class  Application  extends  GrailsAutoConfiguration  {          static  void  main(String[]  args)  {                  GrailsApp.run(Application)          }  }

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

New Configuration API• The grailsApplication.config object now implements grails.config.Config

• Configuration read from Spring PropertySources:• System properties, environment, application.yml etc.

• Built on type conversion and default values• Integration with @Value configuration injection

18

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Configuration API

19

boolean  isFooEnabled  =  config      .getProperty('foo.bar',  Boolean,  true)  

//  or  

@Value('foo.bar')  boolean  isFooEnabled  

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Application Profiles• Extensible project profiles with an API exposing structure• Profile specific commands (run, package, test)• Profile specific plugins• Profile specific project templates and file templates (code generators) backed by

Git• Community maintained profiles and core profiles

20

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Application Profiles• Each profile can have distinct plugins, runtimes and packaging (JAR, WAR etc.)

21

$  grails  create-­‐app  myapp  —profile=web-­‐api    $  cd  myapp  $  grails  war  $  java  -­‐jar  target/myapp.war  

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Profile Repository• https://github.com/grails-profiles/grails-profile-repository • Profiles checked out locally and periodically updated• Profiles wrap code generation infrastructure

22

$  grails  create-­‐controller  foo  

Profile  .getCurrentProfile()  .getCommand('create-­‐controller')  .execute(  'foo'  )

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Application Profiles• Find out the available profiles with grails list-profiles:

23

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Grails 3 - The REST profile• Introduced in Grails 3.0.5• Refined in Grails 3.1 M1• Targeted at building REST applications• REST Specific plugins and commands• No GSP, asset pipeline, UI plugins

24

3.03

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Demo

25

REST Profile

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Grails 3 - REST profile• Profile specific commands:

• create-domain-resource - creates an @Resource domain

• create-restful-controller - Creates a RestfulController

• Default commands provided focused templates

26

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Grails 3 - JSON and Markup Views• Statically compiled, extensible JSON views:

27

json.person  {      name  "bob"  }  

{"person":{"name":"bob"}}

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Demo

28

JSON Views

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Grails 3 - Interceptors• Replace previous Filters mechanism• Compatible with static compilation (@CompileStatic)• Implements the Interceptor trait• Match by convention

• BookInterceptor matches all actions of BookController• Configurable matching with match / matchAll methods

29

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Grails 3 - Interceptors

30

class  MyInterceptor  {      MyInterceptor()  {            matchAll()            .except(controller:  "user")      }      boolean  before()  {  true  }      boolean  after()  {  true  }      void  afterView()  {}  }

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Demo

31

Interceptors

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Evolution of Metaprogramming

32

Runtime Metaprogramming

(ExpandoMetaClass)

Compile time Metaprogramming(AST Transforms)

Traits & Transforms

Grails 1.x Grails 2.x Grails 3.x

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Core Grails Traits• Controller - implemented by all controllers• DomainClass - implemented by all domain classes

• GormEntity - implemented by all GORM entities• Service - implemented by all services• TagLibrary - implemented by all tag libraries• Interceptor - all Grails interceptors

33

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Adding Behaviour with Traits• Use Enhances to add behaviour

34

import  grails.artefact.*  

@Enhances('Controller')  trait  MyTrait  {        void  myNewMethod()  {              …        }  }

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

More on Plugins & Traits

• Session Plug: • “Grails 3.x Inside and Out”

• 12:45 PM• Wednesday (Tomorrow)• See you there!

35

3.03

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Deprecations / Removals• Servlet 2.5 support (no web.xml)• Gant & Current Build System• Integration Tests - Now Geb tests• Metaprogramming - Replaced by Traits & Groovy

extensions• Filters - Replaced by Interceptors

36

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Servlet 3.0 only and no web.xml• Adding new servlets and filters can be done via Spring beans (Ordering with

@Ordered)

37

Closure  doWithSpring()  {{-­‐>          characterEncodingFilter(                    CharacterEncodingFilter)  {                          encoding  ='utf-­‐8'          }  }}

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

What’s coming in Grails 3.1?• Lots to look forward to:

• Refined REST profile• MongoDB 3.0 (Codecs)• Hibernate 5• AngularJS / SPA support• More flexible profile support

o repositories, local profiles etc.

38

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 39

More at ociweb.com/grails

Grails keeps getting better!

Grails 3.1 is scheduled to ship in Q4, 2015. With this new release, you can expect to see even greater

efficiency with Single Page Applications (SPA), REST profiles and more!

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

And next year in Grails 3.x?• Netty profile

• Low memory footprint• Asynchronous• REST• Cloud native

• GORM Async• MongoDB 3.0 async driver support• Lightweight SQL implementation using non-blocking Postgres /

MySQL

40

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Q & A

41

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 42

More at ociweb.com/grails

Don’t forget to stop by OCI’s Table #2 for several chances to win a Grails t-shirt and an

Apple Watch Sport!

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Stay Connected.

Web: grails.orgStackOverflow: http://stackoverflow.com/tags/grails Slack: http://slack-signup.grails.org Twitter: twitter.com/grailsframeworkLinkedIn: http://linkedin.com/groups/Grails-User-Group-39757

43

More at ociweb.com/grails