Reputation: 31
I need to upgrade my grails application from 2.4.4 to 4.0.1 is there any smart way to do it or any kind of help if you can share your experience.
Upvotes: 0
Views: 882
Reputation: 1219
Start by create-app creating a new application. Start the application. Slowly move one set of items at a time and then restart. Start by adding dependiences one at a time then try adding the configurations like create the Datasource and restart. Then move the Domain Objects and then see that you can still start. Then move URL mappings. Then move the related views controllers and services and taglibs and init/Bootstrap. Services and controllers and views need changes. Wait on moving tests until these are all working. Breaking into small pieces and moving them would be the best approach. Then when you have a problem you know what might be the cause.
o Command Objects
Remove @Validateable annotation and replace with:
implements Grails.validation.Validateable
Getter methods not tied to a field now will throw nullable validation errors unless a nullable: true constraint is added
o GSPs
To access constraints in a domain class, use constrainedProperties:
<g:textField name="phone" class="form-control" title="##########" pattern="${domainobject.constrainedProperties.phone.matches}" maxlength="10" placeholder="##########" value="${domainobject?.phone}"/>
To access constraints in a command object, use constraintsMap:
<g:textField name="phone" class="form-control" title="##########" pattern="${searchCommand.constraintsMap.phone.matches}" maxlength="10" placeholder="##########" value="${searchCommand?.phone}"/>
Including templates via relative paths no longer works, use absolute paths
<g:render template="../includes/address"/> to
<g:render template="/includes/address"/>
Change <g:javascript> to <asset:script>
Remove <r:require> statements, which was for resource plugin, now using asset pipeline
Service Import statement for Transactional and other gorm annotations has changed. Added gorm. and now is: grails.gorm.transactions.Transactional
Seem like Grails 3 had some default transactional behavior in Services, but Grails 4 does not Where needed, you will need to add: @Transactional Review documentation here: https://docs.grails.org/latest/guide/services.html
o Notable package name changes
org.codehaus.groovy.grails now org.grails
JSONArray now in org.grails.web.json
WebUtils now in org.grails.web.util
o Grails Link Generator now injected by default to Controller
Remove
def grailsLinkGenerator
Quartz plugin
Add static to current = false
static concurrent = false
Upvotes: 0
Reputation: 481
Søren shared these scripts with me: https://gist.github.com/sbglasius/b0b99e14aabff1965bfeab67ef0231a1
https://gist.github.com/sbglasius/929e37c52c9d2cb7ba14c87e3ff8186e
https://gist.github.com/sbglasius/bb059ab482c3c3e94542cf3dfc6cbca1
I haven't had a chance to try them out myself, but I will be doing the same thing some time this year. I ve done it manually a couple of times before, and it can be tedious. How difficult the upgrade will be a function of:
How many plugins you use that haven't been upgraded or ported to Gradle + the amount of bad unsupported practices * the size of your code base.
In the end it will be worth it though.
Also here's a couple of links I did as post to upgrades. While I did trails 2 to 3 to 4, at this point I would recommend you just go all the way to 4, and skip 3:
https://dev.to/virtualdogbert/grails-2-5-5-to-grails-3-3-10-postmortem-520a
https://dev.to/virtualdogbert/grails-3-3-10-to-4-0-2-postmortem-5kj
Upvotes: 3