ultraq / thymeleaf-layout-dialect

A dialect for Thymeleaf that lets you build layouts and reusable templates in order to improve code reuse
https://ultraq.github.io/thymeleaf-layout-dialect/
Apache License 2.0
719 stars 113 forks source link

When using Gretty with the Thymeleaf Layout Dialect, an exception was thrown when visiting a layout-applied page. #237

Open mklinkj opened 1 year ago

mklinkj commented 1 year ago

Hello.

When running the web server with Gretty.. When accessing the layout page, the following exception is exposed and nothing appears on the web browser screen.

My project environment looks like this

When I run the web project, I run it with the command below.

gradle clean appRun

When I ran Gretty and accessed the page with the layout applied, I definitely saw the aforementioned exception.

However, there are two things that are unusual.

✨ Two unusual things

  1. If I'm using a direct deployment of Tomcat without using Gretty, I don't get the exception.

  2. If I use https://github.com/zhanhb/thymeleaf-layout-dialect, there's no problem running a web project with Gretty.

     // TODO: Using gretty with thymeleaf-layout-dialect causes an exception
     implementation "nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:${thymeleafLayoutVersion}"
     // TODO: If I use the thymeleaf-layout-dialect modified by zhanhb, the exception does not occur.
     // implementation "com.github.zhanhb:thymeleaf-layout-dialect:${zhanhbThymeleafLayoutVersion}"

✨ Example project to see the problem

I've created an example project for you to see the issue.

Thank you. Have a nice day. 👍

ultraq commented 11 months ago

Hey there, sorry to take so long getting back to you on this one as this is an interesting bug and had me stumped for a very long time. However, I gave it another look this weekend and found the issue.

The Gretty plugin is written against Groovy 3, and introduces Groovy 3 JARs into the classloader of the servlet container that is being launched (Tomcat 10 in this case). However, version 3.1.0 and newer of the Thymeleaf Layout Dialect is written in Groovy 4, and so this mixup of Groovy versions causes the issues that you're seeing.

The only workarounds I can think of right now are:

I hope that gives you some options to consider. Thank you again for the bug report and the example project which helped me figure out what was going on 🙇‍♂️

mklinkj commented 11 months ago

Thanks for your answer.

I posted the question in two places, so there’s also an issue on Gretty’s Github. 😅

https://github.com/gretty-gradle-plugin/gretty/issues/289

Have a nice day. 👍