upgrading grails 1.x to 2

71
UPGRADING FROM GRAILS 1.X TO 2.X STORIES AND LESSONS LEARNED Will Buck, web developer, virtuwell Twitter (@wbucksoft) Github (willbuck) Email ([email protected])

Upload: wbucksoft

Post on 17-May-2015

1.126 views

Category:

Technology


0 download

DESCRIPTION

Upgrading your grails app from a previous version to the new world of Grails 2.X Tips on how to prepare, what to do, and gotchas that may pop up. Presented on 7/22/13 at Gr8ConfUS in Minneapolis, MN

TRANSCRIPT

Page 1: Upgrading Grails 1.x to 2

UPGRADING FROMGRAILS 1.X TO 2.X

STORIES AND LESSONS LEARNEDWill Buck, web developer, virtuwell

Twitter (@wbucksoft) Github (willbuck) Email ([email protected])

Page 2: Upgrading Grails 1.x to 2

A LITTLE ABOUT ME(Will Buck)

Page 3: Upgrading Grails 1.x to 2

OBLIGATORY COMPANY SHOUTOUT

Page 4: Upgrading Grails 1.x to 2

MINNESOTA NATIVE

Page 5: Upgrading Grails 1.x to 2

DISNEY WORLD JUNKIE

Page 6: Upgrading Grails 1.x to 2

PRO(?)-AM TRAMPOLINE DODGEBALLER

Page 7: Upgrading Grails 1.x to 2

GRAILS GUY

Page 8: Upgrading Grails 1.x to 2

SHARING TODAY:Case Study: 1.3.7 -> 2.1.0

Page 9: Upgrading Grails 1.x to 2

A LITTLE ABOUT WHAT WE DID8 In-House Plugins (some dependent on others)3 Core Applications (one consumer-facing, two internal)LOTS of testing overhaul

Page 10: Upgrading Grails 1.x to 2

CHIME IN!Many of you have done this, share your knowledge

Page 11: Upgrading Grails 1.x to 2

BRIEF INTRO: WHY AREWE DOING THIS AGAIN?

Page 12: Upgrading Grails 1.x to 2

GRAILS 2.X(Well duh)

Page 13: Upgrading Grails 1.x to 2

What's new in Grails 2.0 and above

Page 14: Upgrading Grails 1.x to 2

TESTABILITYThis would be a primary reason to upgrade.

Grails 2 introduced a *lot* of excellent testing support, including...

In memory GORM (making unit testing criteria Queriespossible)Better Console OutputCleaner test reportsAnnotation based mocking makes code more straight-forward(imho)

Page 15: Upgrading Grails 1.x to 2

SUPPORTSince much of the community is moving forward with Grails 2, it

will be easier to:

Get StackOverflow questions answeredGet a new feature in a pluginFind talented developers familiar with your technologyEtc.

Page 16: Upgrading Grails 1.x to 2

AND MORE!Groovy 1.8 support (or 2.0 in Grails 2.2+)ORM improvements and more options (mongoDB forexample)Better default scaffolding (jQuery and HTML5)Easier date parsingMultiple Data Sources SupportEtc etc etc (read the docs, yo!)

Page 17: Upgrading Grails 1.x to 2

PREPARING TO UPGRADE:BRING THE RIGHT TOOLS

Page 18: Upgrading Grails 1.x to 2

DIRECTORY DIFF TOOLKaleidoscope - http://www.kaleidoscopeapp.com/

BeyondCompare - http://www.scootersoftware.com/

Page 19: Upgrading Grails 1.x to 2

GVMLets you jump between versions with ease

gvm install grails [version]http://gvmtool.net/

Page 20: Upgrading Grails 1.x to 2

SOURCE CONTROLKnow how to hop around and make incremental progress!

Git, Mercurial, maybe SVN

Page 21: Upgrading Grails 1.x to 2

UNIT TESTS

Page 22: Upgrading Grails 1.x to 2

HOW TO BEGIN

Page 23: Upgrading Grails 1.x to 2

START FRESH

Page 24: Upgrading Grails 1.x to 2

SIDE BY SIDEvs

IN-PLACEGenerates new-style meta files w/ proper dependenciesTest both simultaneouslyCommit history will be cleaner - single commit of merge back!

Page 25: Upgrading Grails 1.x to 2

grails upgrade

IS DEAD TO YOU!

Page 26: Upgrading Grails 1.x to 2

GET THE TESTS PASSING FIRST

Page 27: Upgrading Grails 1.x to 2

NOTE: THAT WILL TAKE AWHILE

Page 28: Upgrading Grails 1.x to 2

FIRE IT UP!

Page 29: Upgrading Grails 1.x to 2

MERGING BACK

Page 30: Upgrading Grails 1.x to 2

THE CODEWHAT 2 WATCH 4

Page 31: Upgrading Grails 1.x to 2

COMMON ONESCan largely be found in grails documentation

Upgrading from previous versions of Grails

Page 32: Upgrading Grails 1.x to 2

HSQL -> H2Changes in DataSource.groovy

dataSource { driverClassName = "org.h2.Driver" username = "sa" password = ""}

Page 33: Upgrading Grails 1.x to 2

COMMAND OBJECT @VALIDATEABLE @Validateable class SearchCommand { }

Note - see http://jira.grails.org/browse/GRAILS-9162

Page 34: Upgrading Grails 1.x to 2

LOTS OF LITTLE THINGS

Page 35: Upgrading Grails 1.x to 2

The redirect() method now uses the grails.serverURL configsetting

Page 36: Upgrading Grails 1.x to 2

Public methods in controllers will now be treated as actions. Ifyou don't want this, make them protected or private.

Page 37: Upgrading Grails 1.x to 2

ConfigurationHolder.config -> grailsApplication.config

Page 38: Upgrading Grails 1.x to 2

TESTING - A NEW WORLD ORDER

Page 39: Upgrading Grails 1.x to 2

INHERITANCE -> ANNOTATIONS // Grails 1.x way class myControllerTests extends GrailsUnitTestCase { }

Page 40: Upgrading Grails 1.x to 2

INHERITANCE -> ANNOTATIONS @TestFor(MyController)@Mock([MyDomain])class myControllerTests { void testSomething() { // No need to mockDomain() anymore, just save away! MyDomain testInstance = new MyDomain(property: 'value').save()

def result = controller.get() assert result == testInstance }}

Page 41: Upgrading Grails 1.x to 2

OR CHECK OUT SOME GREAT PLUGINS! // Grails 2.x way @TestFor(MyController)@Build([MyDomain, MyOtherDomain]) //Build-test-data plugin is great!class myControllerSpec extends Specification { // Be Spock-tastic void "testSomething"() { given: "A domain instance to retrieve" MyDomain testInstance = MyDomain.build(name: 'Will.i.am') when: "A call is issued to Controller.get" def result = controller.get()

then: "We get the expected domain instance" result == testInstance }}

Page 42: Upgrading Grails 1.x to 2

COMING SOON!Grails 2.3 - Spock by Default!

New in Grails 2.3

Page 43: Upgrading Grails 1.x to 2

YOU MAY FIND SURPRISES...

Page 44: Upgrading Grails 1.x to 2

Note: if you do have test-pollution...

Ted Naleid's Blog on Finding Test Pollution

Page 45: Upgrading Grails 1.x to 2

TOUGHER / LESS DOCUMENTED GOTCHAS

Page 46: Upgrading Grails 1.x to 2

PLUGIN DEPENDENCY DEFINITION

Page 47: Upgrading Grails 1.x to 2

APPLICATION.PROPERTIES - >BUILDCONFIG.GROOVY

Page 48: Upgrading Grails 1.x to 2

APPLICATION.PROPERTIES (BEFORE)#Grails Metadata file#Sun Mar 25 15:53:36 CDT 2012app.grails.version=1.3.7app.name=patient-applicationapp.servlet.version=2.4plugins.build-test-data=1.1.0plugins.code-coverage=1.1.7plugins.codenarc=0.5plugins.database-migration=1.0plugins.functional-test=1.2.7plugins.greenmail=1.2.1plugins.hibernate=1.3.7plugins.jms=1.2plugins.jmx=0.7plugins.joda-time=1.2plugins.jquery=1.4.1.1plugins.mail=0.9plugins.spock=0.5-groovy-1.7plugins.spring-security-core=1.1plugins.tomcat=1.3.7plugins.ui-performance=1.2.2

Page 49: Upgrading Grails 1.x to 2

BUILDCONFIG.GROOVY (AFTER)plugins { build ":tomcat:$grailsVersion"

compile ":mail:1.0" compile ":greenmail:1.3.2" compile ":build-test-data:2.0.3" compile ":codenarc:0.17" compile (":functional-test:2.0.RC1") compile ":jms:1.2" compile ":jmx:0.7.2" compile ":joda-time:1.4" compile ":spring-security-core:1.2.7.3" compile ":ui-performance:1.2.2"

runtime ":database-migration:1.1" runtime ":hibernate:$grailsVersion" runtime ":quartz:0.4.2"

test ":spock:0.6"}

Page 50: Upgrading Grails 1.x to 2

APPLICATION.PROPERTIES (AFTER)#Grails Metadata file#Mon Mar 18 13:56:54 CDT 2013app.grails.version=2.1.0app.name=patient-applicationapp.servlet.version=2.4

Page 51: Upgrading Grails 1.x to 2

RESOURCES PLUGIN

Page 52: Upgrading Grails 1.x to 2

By default, JS, CSS, images etc are now managed by theresources plugin.

<r:layoutResources> <r:require modules="jquery-ui, blueprint">

Page 53: Upgrading Grails 1.x to 2

This can mean a *lot* of restructuring to your front-end filemanagement.

Page 54: Upgrading Grails 1.x to 2

STRUCTURED PROPERTIES

Page 55: Upgrading Grails 1.x to 2

UNDERSCORES IN DOMAIN VARIABLES// in grails-app/domain/my-packageclass SomeDomain { // A legitimate use case String telephoneNumber String telephoneNumber_areaCode String telephoneNumber_prefix String telephoneNumber_lineNumber

// Accidental oopsies, but won't kill things String name String name_sourceId

// NOW we're talking trouble Date dateOfBirth String dateOfBirth_sourceId}

Page 56: Upgrading Grails 1.x to 2

Discovering the shadowy corners...

Page 57: Upgrading Grails 1.x to 2

TRY DIGGING DEEPER...

Page 58: Upgrading Grails 1.x to 2

AND DEEPER.....

Page 59: Upgrading Grails 1.x to 2

BUT EVENTUALLY...in 1.3.7...

the same???

Page 60: Upgrading Grails 1.x to 2

FIX IT AND LET IT GO

Page 61: Upgrading Grails 1.x to 2

TAKEAWAY POINTS

Page 62: Upgrading Grails 1.x to 2

TAKE YOUR TIME

Page 63: Upgrading Grails 1.x to 2

Try to keep new feature development to a minimum

Page 64: Upgrading Grails 1.x to 2

Do a back-merge all at once, right before finishing. Communicatewith your team!

Page 65: Upgrading Grails 1.x to 2

Take a look for existing docs on how upgrade problems weresolved...

Page 66: Upgrading Grails 1.x to 2

... but know that some problems will be unique to your codebase.

Page 67: Upgrading Grails 1.x to 2

Don't fear the source, love the source.

Page 68: Upgrading Grails 1.x to 2

If all else fails, ask the community if you get stuck!

Page 69: Upgrading Grails 1.x to 2

RESOURCES:

(FYI there wasno part 2)

Grails Docs: Upgrading From Previous VersionsO`Reilly Open Feedback Publishing: Programming GrailsTed Naleids Blog - Upgrading to Grails 2 Unit TestingRob Fletchers Blog - Grails 2 Upgrade Part 1

Technipelago Blog - Grails 1.3.7 to 2.0.1 upgrade experiences

Page 70: Upgrading Grails 1.x to 2

SPECIAL THANKS TO:

Zan ThrashZach LegeinZach LendonColin HarringtonSenthil KumaranTeam @ virtuwelland My wife, Virginia

Page 71: Upgrading Grails 1.x to 2

THANKS FOR LISTENING!Any questions?

Give me feedback! http://tinyurl.com/gr8wbuck13My info (again) Twitter (@wbucksoft) Github (willbuck) Email ([email protected])