Sergio Pro
07/29/2020, 1:16 PM@Import
annotation does not seem to be working for me:
`common.main.kts`:
#!/usr/bin/env -S kotlinc -script --
val greeting = "Hello"
`sample.main.kts`:
#!/usr/bin/env -S kotlinc -script --
@file:org.jetbrains.kotlin.script.util.Import("common.main.kts")
print(greeting) // unresolved reference and nothing to import
Both files are in the same directory and I've tried relative and absolute paths. Am I doing something wrong here?
I know it's possible with kscript
but I would prefer to keep extra dependencies to a minimum. Doesn't kotlin have built-in support for this and I'm totally misunderstanding what @Import
annotation is supposed to do?ilya.chernikov
07/31/2020, 3:17 PMImport
annotation should be accessible without FQN in the versions that support it. so it should work as
@file:Import("common.main.kts")
e.g. here is how it looks in the tests https://github.com/JetBrains/kotlin/blob/1.3.70/libraries/tools/kotlin-main-kts-test/testData/import-test.main.ktsSergio Pro
07/31/2020, 3:18 PMilya.chernikov
07/31/2020, 3:19 PM