casid / jte

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

`No script runtime error` when rendering `kte` templates on latest IntelliJ #260

Closed sureshg closed 1 year ago

sureshg commented 1 year ago

I am using JTE as part of a Gradle pre-compiled script plugin to generate buildconfig and IntelliJ IDE is started showing No script runtime was found in the classpath error . Everything was fine recently and i am not sure since when it started having this IDE issue. Any idea what's happening here? By the way, gradle build is working fine as expected, the issue is only on IDE.

Env

IntelliJ IDEA 2023.2.1 Preview (Ultimate Edition)
         Build #IU-232.9559.10, built on August 9, 2023
         org.jusecase.jte-intellij (2.1.0)
         Kotlin: 232-1.9.0-IJ9559.10
Jte.        :  3.0.2
Gradle      :  8.3-rc-4
Kotlin.     :  1.9.0

JTE Config

// jte  = "3.0.2"
plugins {
  `kotlin-dsl`
  alias(libs.plugins.jte)
  ...
}

jte {
  contentType = gg.jte.ContentType.Plain
  sourceDirectory = sourceSets.main.map { it.resources.srcDirs.first().toPath() }
  generate()
}

dependencies {
  implementation(libs.jte.runtime)
}

IDE Error

No script runtime was found in the classpath: class 'kotlin.script.templates.standard.ScriptTemplateWithArgs' not found. Please add kotlin-script-runtime.jar to the module dependencies.
Screenshot 2023-08-15 at 5 47 46 AM
casid commented 1 year ago

Hmm, that's weird. So I assume it started with the IntelliJ upgrade and worked normally before?

I had a quick look at the plugin and found this: https://github.com/casid/jte-intellij/blob/6193b3870016f42155de503660a2985d761df8ac/src/main/java/org/jusecase/jte/intellij/language/KteKotlinLanguageInjector.java#L293

We explicitly request Kotlin as language here, but there's an overload to startInjtecting that takes a file extension as second parameter. I'd give it a try if this change helps to force Kotlin instead of Kotlin Script:

registrar.startInjecting(KotlinLanguage.INSTANCE, "kt");

Unfortunately I won't be able to test it until somewhere next week.

If you need a fix for it sooner, you could try to check out the plugin, apply the fix, build a local version of the plugin and test with it.

sureshg commented 1 year ago

So I assume it started with the IntelliJ upgrade and worked normally before?

I think so.

registrar.startInjecting(KotlinLanguage.INSTANCE, "kt");

Yup, that did the trick. I built and updated the plugin and it seems ok now.

Screenshot 2023-08-16 at 7 12 09 PM
casid commented 1 year ago

Aww, thanks for testing and the confirmation!

I've applied the fix and published a new plugin version. Will probably take 1-2 days to go through JetBrains Review.