Download - Grails 3.0 Preview
![Page 1: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/1.jpg)
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Grails 3.0 PreviewBy Graeme Rocher
![Page 2: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/2.jpg)
Agenda
§ State of Nation § What’s planned for Grails 2.4? § What’s planned for Grails 3.0? § Summary / Q & A
![Page 3: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/3.jpg)
State of Nation
§ Grails 2.4.3 most recent version § Grails 2.3.x line at 2.3.9 § Hundreds of bugs fixed in the last 3
months § More than 1,100 plugins now for
Grails
![Page 4: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/4.jpg)
!Grails 2.4What’s new?
2.4
![Page 5: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/5.jpg)
Grails 2.4
• Spring 4.0 Upgrade • Java 8 Support • Groovy 2.3 Upgrade • Improved @CompileStatic Support • Asset Pipeline Plugin • Moduralization of Codebase • Hibernate Goodies • GORM & GSP Standalone
5
3.02.4
![Page 6: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/6.jpg)
Spring 4.0 / 4.1
• Native GroovyBeanDefinitionReader (ported from BeanBuilder) – https://spring.io/blog/2014/03/03/groovy-
bean-configuration-in-spring-framework-4 • Spring Web Socket
– http://grails.org/plugin/spring-websocket
6
![Page 7: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/7.jpg)
Groovy 2.3
• Traits • Java 8 • Implicit closure coercion • Lots more!
• http://docs.codehaus.org/display/GROOVY/Groovy+2.3+release+notes
7
![Page 8: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/8.jpg)
Other Notable Updates• Java 8 Support • Hibernate 4.3.5 now default • AspectJ 1.8 with Java 8 support • Eclipse Aether 1.0.0 • Fewer Overall Dependencies
8
![Page 9: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/9.jpg)
Modularization
9
grails-web
grails-web-mvc
grails-web-sitemesh
grails-web-gsp grails-web-jsp
grails-web-servlet
grails-web-common
grails-core
grails-encoder
grails-project-api
grails-validation
![Page 10: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/10.jpg)
Asset Pipeline Plugin• Resources replaced with Asset
Pipeline – https://github.com/bertramdev/asset-
pipeline/wiki/Why-asset-pipeline-over-grails-resources-plugin
• Full documentation – http://bertramdev.github.io/asset-
pipeline/ • Many thanks to David Estes!
10
![Page 11: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/11.jpg)
Standalone• GORM for Hibernate 4 in Spring Boot
– https://spring.io/guides/gs/accessing-data-gorm/ • GORM for MongoDB in Spring Boot
– https://spring.io/guides/gs/accessing-data-gorm-mongodb/ • GSP standalone
– https://github.com/grails/grails-boot/tree/master/sample-apps/gsp
11
![Page 12: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/12.jpg)
@GrailsCompileStatic• Grails-aware version of Groovy’s @CompileStatic
12
import grails.compiler.* !@GrailsCompileStatic class BookController { … }
![Page 13: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/13.jpg)
Maven-style Dependency Management• Use management block to declare managed dependencies
13
!management { dependency "commons-‐logging:commons-‐logging:1.1.3" }
![Page 14: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/14.jpg)
Hibernate Subqueries• Perform nested “in” or “notIn” sub queries that span domain
classes using where queries:
14
def employees = Employee.where { region.continent in ['APAC', "EMEA"] }.id() !def results = Sale.where { employee in employees && total > 50000 }.employee.list()
![Page 15: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/15.jpg)
Hibernate Correlated Subqueries• Declare aliases using “def” for cross query references:
15
def query = Employee.where { def em1 = Employee exists Sale.where { def s1 = Sale def em2 = employee return em2.id == em1.id }.id() } def results = query.list()
![Page 16: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/16.jpg)
Hibernate Column Readers/Writers• Implement custom column readers and writers to transform
data when written or read from the database.
16
class Name { String title static mapping = { title write:'UPPER(?)', read:'REPEAT(title, 2)' } }
![Page 17: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/17.jpg)
Hibernate 4 in Unit Tests (Coming Soon)• Test Hibernate 4 interaction in unit tests
17
import grails.test.mixin.hibernate.* !@TestMixin(HibernateTestMixin) class PersonSpec extends Specification{ void setupSpec() { hibernateDomain([Person]) } … }
![Page 18: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/18.jpg)
GORM for MongoDB 3.0• Support for MongoDB 2.6 • GeoJSON type support • Maps of entities • Full Text Search • Projections using Aggregations • Size queries (sizeEq, sizeLt etc.) • Spring Boot
– https://spring.io/guides/gs/accessing-data-gorm-mongodb/
18
![Page 19: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/19.jpg)
New Maven Plugin 2.4.3• Upgraded to Maven 3.1+ • Rewritten to use Aether for dependency resolution as per
recommendations • Can now be used with multiple versions of Grails:
19
<configuration> <grailsVersion>2.3.8</grailsVersion> </configuration>
![Page 20: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/20.jpg)
Grails 2.4.x TODOs• Grails 2.4.4 - Out Soon • Spring Security Core 2.0 GA • Spring Web Flow Plugin Update • Bug Fixes
20
2.4
![Page 21: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/21.jpg)
!Q & AGrails 2.4
2.4
![Page 22: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/22.jpg)
!The FutureGrails 3.0
3.0
![Page 23: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/23.jpg)
Grails 3.0: Goals
• Embrace Gradle • Abstract Packaging / Deployment • Reach outside the Servlet Container • App Profiles: Netty, Servlet, Batch,
Hadoop • Deployment with run-app / runnable
JARs • Extend the reach of Grails
23
3.03.0
![Page 24: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/24.jpg)
Grails 3.0: Goals
• Build on Spring Boot • Plugin System & Events • Support Multi Project Builds • Support Micro Services • Remove Bloat • Reduce Dependencies
24
3.03.0
![Page 25: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/25.jpg)
Spring IO Platform Reprise
25
Jobs, Steps, Ingestion, Export, Controllers, REST, Channels, Adapters,
WEBINTEGRATION BATCH BIG DATA
SPRING CORE
FRAMEWOR SECURIT GROOV REACTO
DATA
RELATIONA NON-
BOOT
Bootable, Minimal, Ops-Ready
GRAILS XD IO
IO
![Page 26: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/26.jpg)
Spring IO Platform
26
Grails
Spring IO Platform
Spring XD
Spring Foundation
Apps
3rd Party Dependencies
Spring Boot
![Page 27: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/27.jpg)
Spring IO & Grails• What does Spring IO bring to Grails?
– Standardised dependency management – Published BOMs for use with Maven & Gradle – Foundational libraries – See more http://docs.spring.io/platform/docs/current/
reference/htmlsingle/
27
dependencies { compile 'commons-‐lang:commons-‐lang' }
![Page 28: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/28.jpg)
Gradle
• Deprecate existing build system • Replace with Gradle build • Easier now everything is forked in 2.3.x • All the flexibility of a powerful build
system • Separate build plugins can provide
Gradle extensions
28
![Page 29: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/29.jpg)
Plugin Delineation
29
Grails.sh
Static void m
ain
Gradle B
uild
Forked Grails Runtime
test-app
shellrun-app
console
Codegen Plugins
Build Time Plugins
Runtime Plugins
![Page 30: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/30.jpg)
Gradle
• Allow Micro or Monolith Applications • Multi-Project Plugin Architectures • Run individual sub projects • Or run as a whole
30
![Page 31: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/31.jpg)
!Demo Grails 3.0 Gradle
3.0
![Page 32: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/32.jpg)
Spring Boot
• Grails 3.0 to be built on Spring Boot • Boot to handle
• Embedded servers • Runnable JARs • WAR packaging • Scripting / Micro Services
32
![Page 33: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/33.jpg)
Why Spring Boot?
• Handles Fat JAR and embedding • Already supports different runtimes • Includes monitoring and health
checks • Grails can take advantage of Boot
auto configuration
33
![Page 34: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/34.jpg)
Boot Powered Micro Services
34
@Grab("com.h2database:h2:1.3.173") import grails.persistence.* !@Entity @Resource(uri='/books') class Book { String title }
![Page 35: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/35.jpg)
!Demo Grails 3.0 Micro Services
3.0
![Page 36: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/36.jpg)
Deprecations / Removals• Servlet 2.5 support (no web.xml) • Gant & Current Build System • GDoc - Replaced by AsciiDoctor • Integration Tests - Replaced by more
Mixins • Converters / Codecs plugins -
Replaced by Groovy extensions • Filters - Replaced by new mechanism
36
![Page 37: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/37.jpg)
Servlet 3.0 only and no web.xml• Thanks to Spring Boot, new servlets and filters can just be
Spring beans
37
!def doWithSpring = { characterEncodingFilter( CharacterEncodingFilter) { encoding ='utf-‐8' } }
![Page 38: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/38.jpg)
Simplification• Removed
– UrlMappingsFilter – GrailsDispatcherServlet – SimpleGrailsController – Sitemesh Filter
38
![Page 39: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/39.jpg)
Old Grails 2.x Flow
39
UrlMappingsFilterGrailsPageFilter
Decorate Request Forward Request
GrailsDispatherServlet
Delegate Request
GrailsController
![Page 40: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/40.jpg)
Grails 3.0 Flow• GrailsDispatcherSerlvet 50 lines of code in 3.x,
but 545 lines in 2.x
40
DispatcherServlet
Delegate Request
GrailsController
![Page 41: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/41.jpg)
Benefits of Simplification• Less code to maintain • Better performance • Better integration with Spring • Fewer dependencies
• commons-fileupload gone • No internal forwarding
41
![Page 42: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/42.jpg)
Evolution of Metaprogramming
42
Runtime Metaprogramming
(ExpandoMetaClass)
Compile time Metaprogramming(AST Transforms)
Traits & Transforms
Grails 1.x Grails 2.x Grails 3.x
![Page 43: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/43.jpg)
Grails 3.0 & Groovy Traits• Most logic previously added via AST transforms will now be
added by Traits – (Cases not possible as Trait done with transforms)
43
trait Controller { … def withFormat(Closure callable) { … } }
![Page 44: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/44.jpg)
Application Profiles
• Each profile will have distinct plugins, runtimes and packaging (JAR, WAR etc.)
44
!$ grails create-‐app myapp -‐-‐profile=netty $ cd myapp $ grails package $ java -‐jar target/myapp.jar !
![Page 45: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/45.jpg)
Application Profiles
• Extensible 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
45
![Page 46: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/46.jpg)
Profile Repository• All Profiles managed by git • Profiles checked out locally and periodically updated • Profiles wrap code generation infrastructure
46
$ grails create-‐controller foo !Profile .getCurrentProfile() .getCommand('create-‐controller') .execute( 'foo' )
![Page 47: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/47.jpg)
Grails 3.0: Challenges
• Compatibility – Plugins – Build System
• Modularization – Servlet API independence – Refactoring
47
3.0
![Page 48: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/48.jpg)
!Q & AGrails 3.0
3.0
![Page 49: Grails 3.0 Preview](https://reader033.vdocuments.us/reader033/viewer/2022051209/547e7fc0b47959a2508b4b61/html5/thumbnails/49.jpg)
Stay Connected.
!!!!
Web: grails.org StackOverflow: http://stackoverflow.com/tags/grails Twitter: twitter.com/grailsframework LinkedIn: http://linkedin.com/groups/Grails-User-Group-39757 Google+: https://plus.google.com/communities/109558563916416343008