micronaut-views icon indicating copy to clipboard operation
micronaut-views copied to clipboard

Consider providing thymeleaf reflect-config.json for GraalVM Native Image

Open sdelamo opened this issue 3 years ago • 4 comments

Issue description

Executing the micronaut-live-newsletter app with the agent generates at latest the following config:

[
{
  "name":"org.thymeleaf.context.AbstractEngineContext",
  "queryAllDeclaredMethods":true,
  "queryAllPublicMethods":true}
,
{
  "name":"org.thymeleaf.context.IContext",
  "queryAllDeclaredMethods":true}
,
{
  "name":"org.thymeleaf.context.IEngineContext",
  "queryAllDeclaredMethods":true}
,
{
  "name":"org.thymeleaf.context.IExpressionContext",
  "queryAllDeclaredMethods":true}
,
{
  "name":"org.thymeleaf.context.ITemplateContext",
  "queryAllDeclaredMethods":true}
,
{
  "name":"org.thymeleaf.standard.expression.AdditionExpression",
  "methods":[{"name":"<init>","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression","org.thymeleaf.standard.expression.IStandardExpression"] }]}
,
{
  "name":"org.thymeleaf.standard.expression.AdditionSubtractionExpression",
  "methods":[
    {"name":"isLeftAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }, 
    {"name":"isRightAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }
  ]}
,
{
  "name":"org.thymeleaf.standard.expression.AndExpression",
  "queriedMethods":[
    {"name":"isLeftAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }, 
    {"name":"isRightAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }
  ]}
,
{
  "name":"org.thymeleaf.standard.expression.EqualsNotEqualsExpression",
  "queriedMethods":[
    {"name":"isLeftAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }, 
    {"name":"isRightAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }
  ]}
,
{
  "name":"org.thymeleaf.standard.expression.GreaterLesserExpression",
  "queriedMethods":[
    {"name":"isLeftAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }, 
    {"name":"isRightAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }
  ]}
,
{
  "name":"org.thymeleaf.standard.expression.MultiplicationDivisionRemainderExpression",
  "queriedMethods":[
    {"name":"isLeftAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }, 
    {"name":"isRightAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }
  ]}
,
{
  "name":"org.thymeleaf.standard.expression.OrExpression",
  "queriedMethods":[
    {"name":"isLeftAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }, 
    {"name":"isRightAllowed","parameterTypes":["org.thymeleaf.standard.expression.IStandardExpression"] }
  ]}
]

see https://github.com/micronaut-projects/micronaut-views/issues/302

sdelamo avatar Dec 17 '21 12:12 sdelamo

As discussed with Sergio we should review all the "*Expression" and related classes and configure them in the module. The tracing agent only generates config for what's used in the test application but not for everything, so we need to do it so anything that a user uses works.

ilopmar avatar Dec 17 '21 15:12 ilopmar

As I'm working with Thymeleaf now and creating native-image, I could take a look. What was meant by "configure them in the module"?

There are many classes that are easily traced by the GraalVM Tracing Agent. I have some difficulties with OGNLShortcutExpression and OGNLVariableExpressionEvaluator and did not get traced. They do some more trickery with reflection. Perhaps @danielfernandez could help us here? In the end, using Thymeleaf from within a GraalVM native image is really a cool feature.

gijsleussink avatar Dec 19 '23 21:12 gijsleussink

Yes, I like Thymeleaf and use it with native image. However, It is difficult to say what belongs in the module and what belongs in the user application. Yesterday, for example, we had to add this commit setting some classes accessed by Thymeleaf as reflective and providing some config as well.

sdelamo avatar Dec 20 '23 08:12 sdelamo

I added the application specific classes (by using the native-image-agent and running the application) and my application now works as a native image. With that, I agree that it's difficult to say what needs to be added from Thymeleaf or Views and from the user application 🤔

gijsleussink avatar Dec 27 '23 16:12 gijsleussink