Search code examples
grailsgrails-4

Static resource issue with upgrading from grails 3 to 4


We have written a custom jar that implements a limited version of the OpenApi standard used by swagger. This jar uses an ASTTransformer implementation to generate the json file when the project builds, and adds the resulting file to the build/resources/main/public directory of the project.

We have this jar added to our Grails 3 project with the following added to our application.yml

grails:
    resources:
        pattern: '/*.json'

With this setup, we are able to navigate to http://server/projectRoot/openapi_v2.json and the application returns the static file.

We are now migrating the project to Grails 4. Executing the build of the project, the json file is still being generated to the same build directory, however the url no longer returns the file.

I've tried to research to see if anything has changed between Grails 3 and 4 in regards to the application.yml configuration or if something extra is needed.

We did find on https://docs.grails.org/latest/guide/upgrading.html a note about potentially adding sourceResources to the bootRun in the build.gradle, but that does not appear to have fixed it.

So my question is, does anyone know what could be causing Grails 4 to not map correctly to the public static resource, where Grails 3 was able to?


Solution

  • The solution to my issue appears to be around updating the jar project. The client project the generated jar was imported into was upgraded to Grails 4, but the jar project was still Grails 3.

    I upgraded the jar project to Grails 4, changing the...

    bootRun {
        addResources = true
    }
    

    to...

    bootRun {
        // addResources = true
        sourceResources sourceSets.main
    }
    

    Once I did that, recompiled the jar, and imported it into the other project, that project started to successfully serve the generated json out of the project root.