Hi, <@U0CHHN4F4> . I use kotlin scripts in our pro...
# scripting
Hi, @ilya.chernikov . I use kotlin scripts in our project. We have different versions of the script in that project. Every version resides in different package. For example: packageA | --> myscript.kts packageB | --> myscript.kts When I try to build the project I get :
Duplicate JVM class name 'B_main' generated from: Myscript, Myscript
error. In this case I used gradle for the build. I tried with it with custom Kotlin script template as well as with ‘main.kts’ template. The result is the same. I checked in gradle
directory and saw that script generated classes resides on the top level and not in separate packages (
). How can I fix it?
Hi Egor. The
directive is available for scripts, the behaviour here is not different from the regular sources. It is not enough to put scripts into the package directory. to assign the package automatically.
I see. Thanks @ilya.chernikov. Another one. Is there any way to set the name of generated class dynamically? Without using package notation?
Unfortunately, there is no such a mechanism yet. Maybe it should be implemented. There is a somewhat similar issue with imports - https://youtrack.jetbrains.com/issue/KT-37777, so some common mechanism could potentially solve both issues. At the moment it seems you can only solve it, if you supply script sources to the compiler manually, in this case you can use a ScriptSource with the name you like, and it will be used for the class name. It may interfere with IntelliJ support though.
Thanks Illya. This is what we are doing. Kind of. But in our case the names for those scripts the same, because all those are only some versions of initials set of scripts (each version has some modification in some script here and there). So in order for this to succeed we need to use different name for each script in each version/revision. I think this is not an option. Thanks anyway Illya.