Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Migrating from Grails 2 to Grails 3

2.520 Aufrufe

Veröffentlicht am

This presentation was held at the Spring One 2GX 2015 conference in Washington DC.

The presentation explains how to migrate an existing Grails 2 application to the new Spring Boot and Gradle based Grails 3. It covers migrating plugins, applications and features gotchas as well as best praciteces.

The conference presentation also included an extensive live coding section in which I migrated an existing application to Grails 3.

Veröffentlicht in: Software

Migrating from Grails 2 to Grails 3

  1. 1. 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 Migrating from Grails 2 to Grails 3 Michael Ploed - innoQ @bitboss
  2. 2. 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/ Grails 3 is the most major and 
 radical change in the history of Grails 2 + =
  3. 3. 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/ HOW
 TO
 MIGRATE 3
  4. 4. 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/ HOW
 TO
 MIGRATE 4 A Grails application usually consists of the
 application and 
 various plugins
  5. 5. 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/ HOW
 TO
 MIGRATE 5 An application usually integrates with many standard and some self written plugins
  6. 6. 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/ Don’t add complexity. Wait until your major external plugins have been migrated 6
  7. 7. 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/ Grails 3 has different file / directory locations 7 Grails 2 Grails 3 grails-app/conf/BuildConfig.groovy build.gradle grails-app/conf/Config.groovy grails-app/conf/application.groovy grails-app/conf/UrlMappings.groovy grails-app/controllers/UrlMappings.groovy grails-app/conf/BootStrap.groovy grails-app/init/BootStrap.groovy scripts src/main/scripts src/groovy src/main/groovy src/java src/main/groovy test/unit src/test/groovy test/integration src/integration-test/groovy web-app src/main/webapp or src/main/resources/ *GrailsPlugin.groovy src/main/groovy
  8. 8. 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/ Files that are not present in Grails 2.x 8 New File Explanation build.gradle Gradle build script gradle.properties Gradle build properties grails-app/conf/logback.groovy Logging has been extracted from Config.groovy and is now being defined via Logback grails-app/conf/application.yml You can now also configure your application with YAML grails-app/init/PACKAGE_PATH/Application.groovy The Application class that is used by Spring Boot to start the Grails 3 application
  9. 9. 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/ Unneeded files after a successful migration 9 Obsolete File Explanation application.properties Moved to build.gradle (for application name and version) grails-app/conf/DataSource.groovy Merged to application.yml lib Dependency resolution should be used to resolve JAR files web-app/WEB-INF/applicationContext.xml Removed, beans should now be defined in grails-app/ conf/spring/resources.groovy src/templates/war/web.xml No longer needed for Grails 3. Do customization via Spring web-app/WEB-INF/sitemesh.xml Removed, sitemesh filter is no longer present web-app/WEB-INF/tld Removed, can be restored in src/main/webapp or src/ main/resources/WEB-INF
  10. 10. 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/ 10 Before and after interceptors have been removed
 
 They need to be replaced by standalone interceptors
  11. 11. 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/ General migration steps 1/2 11 Grails 2 Grails 3 create-app create-plugin src/java
 src/groovy src/main/groovy grails-app grails-app test/unit test/integration test-unit src/integration- test/groovy
  12. 12. 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/ General migration steps 2/2 12 Grails 2 Grails 3 Fix Build (imports) Config.groovy to application.groovy BuildConfig build.groovy Merge DataSource.groovy Move log4j config to Logback C
 L
 E
 A
 N
 U
 P
  13. 13. 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/ 13 Step 1
 Migrate Plugins
  14. 14. 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/ 14 Mind the Plugin directory on the Grails Website.
 
 It focusses on Grails 1.x - 2.x plugins
 Grails 3 Plugins are on Bintray
  15. 15. 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/ Steps to take for plugin migration There are several steps you have to take for migrating a plugin • Create a new Grails 3 plugin • Copy Sources • Handle the plugin descriptor • Add dependencies to the build • Modify package imports • Migrate configuration • Register ArtefactHandler definitions • Migrate code generation scripts • Delete unnecessary files 15
  16. 16. 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/ Handle Plugin Descriptor You must copy the Plugin descriptor from the Grails2 application to 
 src/main/groovy/grails/plugins/[pluginname]
 After that you have to add the correct package declaration to the plugin descriptor 16 package grails.plugins.recaptcha class RecaptchaGrailsPlugin { … }
  17. 17. 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/ Register Artefact Handler Definitions If you have ArtefactHandler definitions written in Java you have to declare them in src/main/resources/META-INF/grails.factories
 This step can be ignored for Groovy based ArtefactHandlers, Grails detects them. 17 grails.core.ArtefactHandler=grails.plugins.quartz.JobArtefactHandler
  18. 18. 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/ Migrate code generation scripts Old Gant code generation scripts have to be replaced by Code Generation Scripts or Gradle tasks. Simple code generation can easily be migrated to the new code generation API More complex tasks are better of with a migration to Gradle tasks 18
  19. 19. 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/ Simple code generation example 19 includeTargets << grailsScript("_GrailsCreateArtifacts") target(createJob: "Creates a new Quartz scheduled job") { depends(checkVersion, parseArguments) def type = "Job" promptForName(type: type) for (name in argsMap.params) { name = purgeRedundantArtifactSuffix(name, type) createArtifact(name: name, suffix: type, type: type, path: "grails-app/jobs") createUnitTest(name: name, suffix: type) } } setDefaultTarget 'createJob'
  20. 20. 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/ Gradle Tasks for complex generation scripts 20 import … class RunQueryCommand implements ApplicationCommand { @Autowired DataSource dataSource boolean handle(ExecutionContext ctx) { def sql = new Sql(dataSource) println sql.executeQuery("select * from foo") return true } } > grails create-command run-query
  21. 21. 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/ Command can be added to classpath in build.gradle 21 buildscript { … dependencies { classpath "org.grails.plugins:myplugin:0.1-SNAPSHOT" } } … dependencies { runtime "org.grails.plugins:myplugin:0.1-SNAPSHOT" } > grails run-query
  22. 22. 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/ 22 Step 2
 Migrate Application
  23. 23. 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/ Steps to take for application migration There are several steps you have to take for migrating a application • Create a new Grails 3 application • Copy Sources • Add dependencies to the build • Migrate Configuration • Migrate web.xml Modifications to Spring • Migrate static assets not handled by Asset pipeline • Migrate Tests • Delete unnecessary files 23
  24. 24. 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/ 24 Step 3
 Test intensively
  25. 25. 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/ Let’s migrate an application 25
  26. 26. 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/ Recap - Migration Steps 26 Plugins App Test
  27. 27. 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 Thank You! Michael Ploed - innoQ 
 Twitter: @bitboss Slides: http://slideshare.net/mploed

×