kscripting / kscript

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

Unresolved reference: encodeToByteArray #387

Closed quentinmarciset closed 1 year ago

quentinmarciset commented 1 year ago

Hello,

I am trying to migrate kscript from 3.0.2 to 4.1.1.

kscript --package main.kt gives me :

e: /Users/xxx/.cache/kscript/package_cae9de924acff818e8f187607f38c411/build.gradle.kts:42:20: Overload resolution ambiguity: 
public open fun write(p0: ByteArray!): Unit defined in java.io.FileOutputStream
public open fun write(p0: Int): Unit defined in java.io.FileOutputStream

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/xxx/.cache/kscript/package_cae9de924acff818e8f187607f38c411/build.gradle.kts' line: 34

* What went wrong:
Script compilation errors:

  Line 34:         val lineSeparator = System.getProperty("line.separator").encodeToByteArray()
                                                                            ^ Unresolved reference: encodeToByteArray

  Line 42:         fileStream.write(lineSeparator)
                              ^ Overload resolution ambiguity: 
                                  public open fun write(p0: ByteArray!): Unit defined in java.io.FileOutputStream
                                  public open fun write(p0: Int): Unit defined in java.io.FileOutputStream

2 errors

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

The write() issue is caused by the unresolved encodeByteArray()

I can't figure out why it can't resolve it. No issue on kscript v3.0.2.

aartiPl commented 1 year ago

Please add std lib to the dependencies, add proper imports for extension functions and recheck.

@file:DependsOn("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.21")

I had a similar issue, so maybe it is the cause of the issue.

If that's the case, I will add std lib to the classpath by default in the next version of kscript.

quentinmarciset commented 1 year ago

Unfortunately this provides the same result. Already tried with different kotlin-stdlib versions.

aartiPl commented 1 year ago

Does it happen only when you are packaging the script or also during the normal execution? Please provide a small test case reproducing the issue.

aartiPl commented 1 year ago

I have tested it in kscript 4.1.1 with only the following:

 val lineSeparator = System.getProperty("line.separator").encodeToByteArray()

And it seems to work as required, without any other imports or dependencies.

Closing as: unable to reproduce.