Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nedtwigg opened this issue Sep 6, 2023 · 2 comments
Open

Comments

@nedtwigg
Copy link
Contributor

nedtwigg commented Sep 6, 2023

Using 3.1.0, we are having a great experience with:

  • TemplateEngine.createPrecompiled
  • and also with
val codeResolver = DirectoryCodeResolver(CWD.server("src/main/jte"))
TemplateEngine.create(codeResolver, Paths.get("build/jte-classes"), ContentType.Html).apply {
  setBinaryStaticContent(true)
}

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?

public void compile(String[] files, List<String> classPath, TemplateConfig config, Path classDirectory, Map<String, ClassInfo> templateByClassName) {
K2JVMCompilerArguments compilerArguments = new K2JVMCompilerArguments();
compilerArguments.setJavaParameters(true);
compilerArguments.setNoStdlib(true);

@casid
Copy link
Owner

casid commented Sep 7, 2023

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
Copy link

ylemoigne commented Dec 13, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants