Grails 4 Resources

So you’ve spent a day or two carefully migrating your Grails 2.4.4 application to Grails 4.0.2. Yet you find that the files in src/main/webapp aren’t accessible from your views. Annoying right!

I’m sure this is documented somewhere, but I’m damned if I could find it again. The solution is to add a reference to them in your application.yml file:

grails:
    resources:
        pattern: /**

Update: After further reading I find this (in section 3.3.2, Step 7):

If you have static assets in your web-app directory of your Grails 2.x application such as HTML files, TLDs etc. these need to be moved. For public assets such as static HTML pages and so on these should go in src/main/resources/public.

TLD descriptors and non public assets should go in src/main/resources/WEB-INF.

As noted earlier, src/main/webapp folder can also be used for this purpose but it is not recommended.

http://docs.grails.org/3.2.3/guide/single.html#upgrading2x

I have now updated my project and moved everything from /src/main/webapp into grails-app/assets folders. I’ve also replaced all instances of the <g:javascript> tag with <asset:javascript>. This gives the added bonus that, in Intellij IDEA, one can ctrl-click the file name and it links to the file.