ultraq / thymeleaf-layout-dialect

A dialect for Thymeleaf that lets you build layouts and reusable templates in order to improve code reuse

Home Page:https://ultraq.github.io/thymeleaf-layout-dialect/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assemble fatjar give problem with dialect

stripcode opened this issue · comments

Hello.
This happened when I assembled fatjar for micronaut(3.1.0) app for deploy to AWS Beanstalk. I run java -jar fatjar. If I run my app in Idea(without jar) - everything is ok(dialect works).

Снимок экрана 2021-10-12 в 23 21 45
Снимок экрана 2021-10-12 в 23 23 12
Снимок экрана 2021-10-12 в 23 25 21

Huh, that's an interesting one. It looks like Micronaut has its own Thymeleaf views and the like: https://micronaut-projects.github.io/micronaut-views/latest/guide/#thymeleaf This is a new one to me, I'll have to take some time to look into this 🤔

@ultraq I created a project with this case if you don't have free time or you don't know micronaut https://github.com/stripcode/micronaut-thymeleaf-layout-dialect

Thanks for the example repo - it's a huge help and with it I was able to reproduce the problem!

Taking a look at the generated JAR, I think the issue is that Groovy doesn't know about the getOrCreate extension method. For Groovy libraries to be able to declare extension methods like getOrCreate, they use a special file that lives in /META-INF/services/org.codehaus.groovy.runtime.ExtensionModule. thymeleaf-layout-dialect has one, and groovy-extensions that is a dependency of this project has one. When the shadow plugin creates the fat JAR the name clash forces shadow to choose one of these files, and the default behavious is for the layout dialect's file to win - getOrCreate however is defined by the groovy extensions dependency.

Luckily the shadow plugin knows that such clashes can happen, and can be configured to handle these. Looking through their user guide, there's a built-in option specifically for Groovy extension modules, so you can include the following config in your build.gradle file:

shadowJar {
  mergeGroovyExtensionModules()
}

From: https://imperceptiblethoughts.com/shadow/configuration/merging/#merging-service-descriptor-files

Adding that config fixed the problem in the example project you provided 👍

Thanks a lot. I checked that advice. It resolved my problem. Great work!