kscripting / kscript

Scripting enhancements for Kotlin
MIT License
2.07k stars 124 forks source link

Don't work @file:Import("absolute/path/to/myutils.kt") #393

Open lsmobile opened 1 year ago

lsmobile commented 1 year ago

An attempt to include my utils per @file:Import("absolute/path/to/myutils.kt") doesn't work. More precisely: Unresolved reference: myFunction

aartiPl commented 1 year ago

Please provide additional information:

I have tested it with kscript 4.2.1, and both (absolute and relative) imports work.

lsmobile commented 1 year ago

It works in terminal, but it doesn't work in IDEA.

myutils.kt:

fun myprint(text: String) { println(text) }

myscript.kts:

#!/usr/bin/env kscript
@file:Import("/absolute/path/to/myutils.kt")
myprint("test")

build.gradle.kts:

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.7.21"
}
repositories {
    mavenLocal()
    mavenCentral() 
}
dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib")
    implementation("org.jetbrains.kotlin:kotlin-script-runtime:1.7.21")
    implementation("io.github.kscripting:kscript-annotations:1.5.0")
}
sourceSets.getByName("main").java.srcDirs("src")
sourceSets.getByName("test").java.srcDirs("src")

Response: e: /home/user/.cache/kscript/idea_4fc...aa4/src/myscript.kts: (5, 1): Unresolved reference: myprint