So, I have some custom scripts defined, whose scri...
# scripting
s
So, I have some custom scripts defined, whose script templates are in module A. In module B, which depends on module A both via
implementation
and
kotlinSCriptDef
, I have some custom scripts committed as resources (
src/main/resources/default.rules.kts
). Unfortunately, IDE auto-completion is not working for that script resource. Is there a way to make it work?
v
hm do you have a marker file as part of your module A jar? please share your Kotlin Scripting settings page and IDEA version
s
Yes, I do have marker files... but give my a second, I just moved them, and maybe I forgot to rename the marker files...
πŸ‘€ 1
No, while I've moved the template files, the package names stayed the same, so that should work. I have files like
Copy code
tils/script-how-to-fix/src/main/resources/META-INF/kotlin/script/templates/org.ossreviewtoolkit.reporter.HowToFixTextProviderScriptTemplate.classname
utils/script-notifications/src/main/resources/META-INF/kotlin/script/templates/org.ossreviewtoolkit.notifier.NotificationsScriptTemplate.classname
utils/script-rules/src/main/resources/META-INF/kotlin/script/templates/org.ossreviewtoolkit.evaluator.RulesScriptTemplate.classname
Copy code
IntelliJ IDEA 2026.1.3
Build #IU-261.25134.95, built on June 3, 2026
Ah, the settings dialog did not show any custom script definitions until I clicked "Search Definitions". Now it seems to work! Is that really something that needs to be done manually, and is not done e.g. on Gradle sync?
v
I changed some things with this recently, the following EAP version (releasing today or tomorrow) gonna have these changes, let's see how it works for you. I'll ping you in this thread when it's available
πŸ‘πŸ» 1
meanwhile could you please share what are you tinkering with scripts? it'd help me to understand our user
s
I'm working on https://github.com/oss-review-toolkit/ort, which contains a policy rule engine leveraging a Kotlin DSL.
πŸ‘€ 1
thank you color 1
BTW, is it correct that auto-completion would not work if the script definition and the custom script resource would be in the same module? I.e. I always have to depend on the module with the definitions?
v
no, you can always specify your definition fqn and classpath via Kotlin Scripting settings panel. and in the eap I mentioned before there is an inspection and quickfix for that
s
Ah, ok, but adjusting settings manually is not an option for me. Everything has to work out of the box after freshly importing the Gradle project.
So with that premise, I need the module dependency, correct?
v
you need a dependency with a jar that has packed marker file
πŸ‘πŸ» 1
s
And do I need a
kotlinScriptDef
dependency, like
kotlinScriptDef(projects.utils.scriptRulesUtils)
, or is
implementation(projects.utils.scriptRulesUtils)
enough, if
projects.utils.scriptRulesUtils
contains the marker file and script template definition?
FYI, here are some changes in that regard, I hope they're correct: https://github.com/oss-review-toolkit/ort/pull/11951
BTW, I'm running into a weird situation now: Two script files in the same module, where for one highlighting works, but not for the other. How can this be?
I tried restarting IntelliJ / reopening the file, but that did not help.
After "Invalidate and Restart", both files are broken now 😞
I can't get it to work anymore. Any help would be appreciated @Vladislav Koshkin.
Ok, this drives my crazy: It works again if I click on "Move file to source root" once, and then move the file back from
kotlin
to
resources
.
v
Hi, I'll take a look later today
πŸ™πŸ» 1
s
You can clone the project from https://github.com/oss-review-toolkit/ort and then look at the file at
evaluator/src/main/resources/rules/osadl.rules.kts
.
🀝 1
v
hi, I'm still taking a look, need some more time
πŸ™πŸ» 1
i
Hi @Sebastian Schuberth. Sorry for the long delay. Unfortunately, if I understand things correctly, we don't have a good generic solution for the problem at the moment. Basically the main problem is this line: it uses the runtime-only utility dependenciesFromCurrentContext, and we don't have an equivalent one that works in the IDE. We're contemplating solutions to this problem for quite some time already, but haven't yet come up with any reasonable decent and safe one. But I hope we'll eventually will. There are some ways for you to code such a solution tailored for your needs via an implementation of the
ScriptDefinitionsProvider
interface in a IntelliJ plugin. But it is likely not a simple way.
s
Thanks for coming back to me @ilya.chernikov. Would it make a difference if I tried to specify dependencies explicitly? Basically, I only need those dependencies that provide the default imports.
i
Well, the compilation configuration should, at the end, contain the dependencies fully resolved to files, so theoretically - yes, you can put there the full paths of jars and in this case, the IDE should pick them up as well as the compiler. But how practical it is - I don't know. Ideally, we should have a scheme of specifying the names of the artifacts needed, and then compile-side and ide-side code should use different strategies for resolving these artifacts. This is how it currently works for
@DependsOn
annotations. But unfortunately, some more generic mechanism is missing.