upgrading grails 1.x to 2

Post on 17-May-2015

1.126 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

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

UPGRADING FROMGRAILS 1.X TO 2.X

STORIES AND LESSONS LEARNEDWill Buck, web developer, virtuwell

Twitter (@wbucksoft) Github (willbuck) Email (wbucksoft@gmail.com)

A LITTLE ABOUT ME(Will Buck)

OBLIGATORY COMPANY SHOUTOUT

MINNESOTA NATIVE

DISNEY WORLD JUNKIE

PRO(?)-AM TRAMPOLINE DODGEBALLER

GRAILS GUY

SHARING TODAY:Case Study: 1.3.7 -> 2.1.0

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

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

BRIEF INTRO: WHY AREWE DOING THIS AGAIN?

GRAILS 2.X(Well duh)

What's new in Grails 2.0 and above

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)

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.

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!)

PREPARING TO UPGRADE:BRING THE RIGHT TOOLS

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

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

GVMLets you jump between versions with ease

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

SOURCE CONTROLKnow how to hop around and make incremental progress!

Git, Mercurial, maybe SVN

UNIT TESTS

HOW TO BEGIN

START FRESH

SIDE BY SIDEvs

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

grails upgrade

IS DEAD TO YOU!

GET THE TESTS PASSING FIRST

NOTE: THAT WILL TAKE AWHILE

FIRE IT UP!

MERGING BACK

THE CODEWHAT 2 WATCH 4

COMMON ONESCan largely be found in grails documentation

Upgrading from previous versions of Grails

HSQL -> H2Changes in DataSource.groovy

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

COMMAND OBJECT @VALIDATEABLE @Validateable class SearchCommand { }

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

LOTS OF LITTLE THINGS

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

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

ConfigurationHolder.config -> grailsApplication.config

TESTING - A NEW WORLD ORDER

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

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 }}

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 }}

COMING SOON!Grails 2.3 - Spock by Default!

New in Grails 2.3

YOU MAY FIND SURPRISES...

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

Ted Naleid's Blog on Finding Test Pollution

TOUGHER / LESS DOCUMENTED GOTCHAS

PLUGIN DEPENDENCY DEFINITION

APPLICATION.PROPERTIES - >BUILDCONFIG.GROOVY

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

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"}

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

RESOURCES PLUGIN

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

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

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

STRUCTURED PROPERTIES

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}

Discovering the shadowy corners...

TRY DIGGING DEEPER...

AND DEEPER.....

BUT EVENTUALLY...in 1.3.7...

the same???

FIX IT AND LET IT GO

TAKEAWAY POINTS

TAKE YOUR TIME

Try to keep new feature development to a minimum

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

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

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

Don't fear the source, love the source.

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

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

SPECIAL THANKS TO:

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

THANKS FOR LISTENING!Any questions?

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

top related