Can't import `kotlin.io.path` . Tried invalidating...
# getting-started
n
Can't import
kotlin.io.path
. Tried invalidating caches and restart. Still no luck. Any idea on how to make this work?
k
What is it you actually want to do? Path is in java.io.file.Path. Kotlin adds extension functions to the Path class. These extension functions are declared in kotlin.io but are implicitly imported so you don't have to.
n
I just want to use this
Path
constructor, from Kotlin's standard library, instead of Java's
Paths.get()
method. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io.path/
k
This was introduced in Kotlin 1.5. Are you using an IDE plugin for the latest version?
i
You need to depend on
kotlin-stdlib-jdk7
or
-jdk8
to use
kotlin.io.path
package. Usually stdlib dependencies are added automatically by Kotlin gradle plugin, but sometimes gradle plugin fails to determine that it's ok to use
kotlin-stdlib-jdk8
and adds a dependency on
kotlin-stdlib
only.
n
@Klitos Kyriacou Yes, I am using the latest version.
@ilya.gorbunov Adding
kotlin-stdlib-jdk7
does the job. Thank You so much. But it is really confusing for a beginner to understand why something from the
stdlib
works and why it doesn't.
179 Views