casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
748 stars 56 forks source link

Kotlin standard library errors with kte and Gradle continuous build #271

Open nedtwigg opened 1 year ago

nedtwigg commented 1 year ago

Using 3.1.0, we are having a great experience with:

Precompiled runs great in prod, the DirectoryCodeResolver gives us great near-instant hotreload locally, with both .jte and .kte.

The only problem we have is with Gradle continuous build. We have a hotreload setup that uses continuous build to restart the server anytime our business logic changes. And for some reason, it is erroring out on .kte templates like so:

  rootCause=gg.jte.TemplateException: Failed to compile template, error at pages/Admin/adminTrialShow.kte:1
@file:Suppress("ktlint")
/Users/ntwigg/Documents/dev/diffplugdotcom/server/build/jte-classes-73184/gg/jte/generated/ondemand/pages/Admin/JteadminTrialShowGenerated.kt:1:7
Reason: Cannot access built-in declaration 'kotlin.Suppress'. Ensure that you have a dependency on the Kotlin standard library
    at gg.jte.compiler.kotlin.KotlinClassCompiler.compile(KotlinClassCompiler.java:45)
    at gg.jte.compiler.TemplateCompiler.precompileClasses(TemplateCompiler.java:122)
    at gg.jte.compiler.TemplateCompiler.precompile(TemplateCompiler.java:94)
    at gg.jte.compiler.TemplateCompiler.load(TemplateCompiler.java:50)
    at gg.jte.TemplateEngine.lambda$resolveTemplateOnDemand$0(TemplateEngine.java:354)
    at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1916)
    at gg.jte.TemplateEngine.resolveTemplateOnDemand(TemplateEngine.java:347)
    at gg.jte.TemplateEngine.resolveTemplate(TemplateEngine.java:337)
    at gg.jte.TemplateEngine.render(TemplateEngine.java:228)

It's strange because the same code works great when we run it without continuous build. Not necessarily a JTE issue, but I wonder if setNoStdlib here ought to be false instead of true?

https://github.com/casid/jte/blob/f53fb9584e7d8526ebc7efba581efad378d3782f/jte-kotlin/src/main/java/gg/jte/compiler/kotlin/KotlinClassCompiler.java#L25-L28

casid commented 1 year ago

Hmm, the documentation says Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath, which sounded good to me, when I intitially added Kotlin support. However, I'm not a heavy Kotlin or Gradle user, so that was rather a gut decision than a well backed one from experience.

Maybe you could try to change this line, make a snapshot build and see if it is working afterwards?

ylemoigne commented 9 months ago

Hello @casid

I tried to set the noStdLib to false and rebuild. It did not fix the issue.

To give more information, I use gradle 8.5 with quarkus plugin. I have the error either by launching quarkusDev or quarkusBuild quarkusRun ; so for me it does not seems to be tied to continous build mode. And it doesn't seem to be only the kotlin stdlib but the whole classpath that have issue.

(So it may be a separe problem)