I'm really struggling with scripting - how can I d...
# scripting
s
I'm really struggling with scripting - how can I define which files my custom script can access? I am getting unresolved reference for everything. I have my project as follows: • example/ <-- example implementation of common ◦ assets/ <-- scripts in here • scripts/ <-- script definition • common/ <-- common data And my dependencies are
scripts -> common -> example
My script file in
assets
cannot see any of the kotlin files in
example
or
common
Here is my script definition:
Copy code
@KotlinScript(
    fileExtension = "udea.kts",
    compilationConfiguration = UdeaScriptConfiguration::class,
)
abstract class UdeaScript

object UdeaScriptConfiguration : ScriptCompilationConfiguration({
    // Common defaults for engine scripts
    defaultImports(
        "kotlin.math.*",
        "com.badlogic.gdx.math.*",
        "dev.wildware.udea.ecs.component.*",
        "dev.wildware.udea.dsl.*",
        "dev.wildware.udea.dsl.blueprint",
        "dev.wildware.udea.assets.*"
    )

    ide {
        acceptedLocations(ScriptAcceptedLocation.Everywhere)
    }

    jvm {
        jvmTarget("17")
        dependenciesFromCurrentContext(wholeClasspath = true)
    }

    compilerOptions.append("-Xcontext-sensitive-resolution")
    baseClass(UdeaScript::class)
}) {
    private fun readResolve(): Any = UdeaScriptConfiguration
}
image.png
What is the missing piece?
@Ilya Muradyan Are you around? Sorry for ping, I am completely blocked by this.
Does IDEA have ANY kind of debugging for custom scripts? I feel so in the dark here..
i
Hi! Sorry, I'm not very much knowledgeable about scripts 😞 I hope @Vladislav Koshkin or @ilya.chernikov could help better
👍 1
Is your script
test_leve.udea.kts
under some source root?
This package you try to use (dev.wildware.udea.assets.*) - is it a part of your sources or rather a maven artifact?
s
My script is under a sub-module
And the package is in the
common
module
i
Hm, but it's not under a source root
I think it may matter
s
IIRC scripts should not be under source root
In fact, if I put it under a source root, I see this:
i
Ok.. I'm then a bit lost in how script should find dependencies. Probably Vlad or Ilya will clarify
What is you try to specify some concrete deps instead of
dependenciesFromCurrentContext(..)
?
s
I wouldn't know what to put in there
This is super strange because it actually does compile and run
Just the IDE doesn't offer any help
@ilya.chernikov Hey could you please assist with this?
I swear its completely broken. Even if I include a function within my script defintion, I cannot call it from my script
image.png
If I move my scripts to
resources
, they can access the files within the project itself, but not any dependencies...
The
defaultImports
don't work either
None of it works
It's like my
@KotlinScript
is not being picked up at all
v
Hi, could you please show Kotlin Scripting settings tab?
and what's your idea version?
s
IntelliJ IDEA 2025.2.3 (Ultimate Edition)
I clicked "Scan classpath" and it discovered my script
v
does the highlighting work?
and everything?
I guess we need to think of some notification when custom script definition is in file extension 🤔
s
image.png
I can see basic syntax highlighting
But it does not discover any of my classpath
v
let's try some things out: when you right-click in script edtior, is there an action "Reload script configuration"?
s
Yes
v
click it
s
Okay
Still cannot access classpath
Still can't access the method in the abstract class
Is there a litmus test of some compilation configuration that I can add that will prove whether it is loaded against my script or not
I'm pretty sure its not loaded at all as non of the default imports work
And context sensitive resolution doesn't work either
v
doesn't it work as well for freshly created scripts?
s
So with a newly created script I can actually access the
weCantCallThis
method
But still no classpath
I can access the direct classpath of the
example
module, but not the
common
module
Context sensitive resolution is now working also
image.png
Which I'm very happy about
Just the classpath now
v
okay, so to fix it for old scripts - you need to reset caches I think let's deal with the classpath
s
That's a bug I assume?
Oh no
Resetting caches removes the script definition from the IDE
Now its completely broken again
v
hm, my bad scan the classpath again then
s
I scanned classpath and clicked the "reload script definition"
And now it still doesn't work
v
how did you reset cache?
s
Invalidate caches and restart
v
I see, let's deal with the classpath first. go to Actions > Registry and find the flag:
kotlin.k2.scripting.show.modules
then go to Project Settings > Modules, there you will see your script modules with some classpath let's also create a new script and see what will be on the classpath
s
I don't see "Actions"
v
it's a tab when you shift shift
s
this?
v
yes, perfect could you please create a new script?
s
Done
v
off topic but all of this will migrate to kotlin scripting settings eventually, but for now it's like this
s
image.png
v
is there your definition in the kotlin scripting setting tab?
this thing tells that your script was resolved with basic ".kts" definition
s
yes
v
instead of udea.kts
hm let me think
s
Seems like its simply broken to me 😅
Do you think this is the bug, if you look, it's being picked up twice
Highlighted and at the bottom
Manually deleting the top definitions got us back to where we were earlier
But still no classpath
v
show me the classpath of the bottom one please?
s
Lots on there now
None of my classpath though
v
it's dues to the
dependenciesFromCurrentContext(wholeClasspath = true)
remove the Default Kotlin script one row with
-
minus button at the top
s
I removed all of them
v
did it work? I mean highlighting
s
I can access
weCantCallThis()
but not any of the classpath
I can also access the
main
source set of the
example
project
But nothing else
The weirest part for me, this works fine on another project, which uses the same definition, but it doesn't even have the script definition loaded
Very strange huh
It doesn't actually have the script definition, as context sensitive resolution isn't working, for example.
But it loads all the classpath anyway
Very strange dependencies here
Just referencing itself
v
what's inside?
s
Inside what?
v
of this
s
this?
None of the classpath loaded - but it works anyway 😅
v
But nothing else
but what are you trying to access?
s
dependencies of
example
module
For example
common
v
but is there a .jar containing example module on your classpath?
s
These are in my
example
project
v
no,no I mean here:
because that the only thing that matter for script classpath
s
No there is no mention of it
I don't know if this would be easier, but all of my code is on a branch https://github.com/wildware-uk/Udea/tree/example
v
haha yes, definitely!
cloning
s
example
is the module,
scripts
is the script definitions,
common
is the common code that I want to include
btw I tried removing the depenciesFromClasspath you may need to add that back
Just pull again
example
branch
v
I think, I see your point. I need to clarify how
dependenciesFromCurrentContext
works. But I would expect the module that holds you script definition to be included into the classpath, but not it's transitive dependencies. I added TestingClass to the same location as your scriptDefinition, and it's available for completion and got resolved
s
That's interesting
Should be noted that the evaluation works absolutely fine
The classpathh is loaded correctly and it compiles and executes correctly
I will try moving the script def into common module
and then I can include the class context reference
(That's what happens at evaluation)
Now my IDEA can't find the script at all 😭 @Vladislav Koshkin
Okay, I moved the script def into common and deleted it from scripts, then restarted and it seems to be working
image.png
K 2
🙌 1
And the default imports are FINALLY working
👍 1