https://kotlinlang.org logo
s

Sebastian Schuberth

10/13/2022, 8:00 AM
After upgrading to Kotlin 1.7.20 I started to get
w: Script 'osadl.rules.kts' is not supposed to be used along with regular Kotlin sources, and will be ignored in the future versions by default. (Use -Xallow-any-scripts-in-source-roots command line option to opt-in for the old behavior.)
for a script that's committed as a resource in a Kotlin project (see https://github.com/oss-review-toolkit/ort/blob/osadl-rules/evaluator/src/main/resources/rules/osadl.rules.kts). What's this supposed to tell me? I mean, the script is not in a source root of Kotlin source set after all...
b

Big Chungus

10/13/2022, 8:10 AM
Resources are still sources since they are added to the classpath. But in your case I think the warning can be safely ignored.
s

Sebastian Schuberth

10/13/2022, 8:24 AM
So, since we treat warnings as errors my only chance is to opt-in to
-Xallow-any-scripts-in-source-roots
, right? Or can I place the script elsewhere to avoid this?
b

Big Chungus

10/13/2022, 8:25 AM
Are you using it in your program? If not, then just move it out of resources, kotlin and java directories
s

Sebastian Schuberth

10/13/2022, 8:26 AM
Yes, I'm using it in the same program / module.
b

Big Chungus

10/13/2022, 8:27 AM
Then yeah, that compiler flag seems to be the only option. Which is still safe since you don't depend on the script being compiled and available for your kotlin code to call
👍🏻 1
Although ideally kgp should hide files in resources from the compiler somehow
At the moment it cannot differentiate between kotlin sources and resources directories.
s

Sebastian Schuberth

10/13/2022, 8:49 AM
Thanks!
However, with
-Xallow-any-scripts-in-source-roots
I'm now running (again) into https://youtrack.jetbrains.com/issue/KTIJ-22806. Do you also have a recommendation about a work-around for that? That issue also seems to be somehow classpath-related.
b

Big Chungus

10/13/2022, 9:38 AM
This is hacky, but you could move script out of resources and then add it into classpath on JvmRun and Jar tasks
This would effectively hide it from compilations
s

Sebastian Schuberth

10/13/2022, 9:48 AM
And I wouldn't get auto-completion for the script when editing it in the IDE, right?
b

Big Chungus

10/13/2022, 9:49 AM
You would. Scripts are standalone entities. You cn have a kts in a npm project and still have autocompletion
i.e. Autocompletion has nothing to do with gradle
54 Views