0

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?

Taplar
  • 24,788
  • 4
  • 22
  • 35
  • "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..." - Is your build setup to put the json file in the jar file in the same place it was when you were using Grails 3? – Jeff Scott Brown Jan 15 '20 at 22:39
  • There is nothing specific to the project around when to generate the file. The generation of the file is driven off of the implementation of the `performInjectionOnAnnotatedClass` method of the @AstTransformer annotation. @JeffScottBrown Edit: the class implements the `GlobalClassInjector` – Taplar Jan 15 '20 at 22:42
  • Mmm, I did just notice that the `build.gradle` for the jar project, not the one the jar is included in, has the `addResources = true` in it. I may have to see if fixing that and recompiling the jar with grails 4 makes a difference. – Taplar Jan 15 '20 at 22:48
  • @JeffScottBrown Well, crud. That looks like it was it. LoL. I feel stupid. I wouldn't have thought the jar settings would have affected the project the jar is imported into. – Taplar Jan 16 '20 at 15:16

1 Answers1

0

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.

Taplar
  • 24,788
  • 4
  • 22
  • 35