Why don't I have the `AutoCloseable.use(...)` fun...
# announcements
c
Why don't I have the
AutoCloseable.use(...)
function? It should be there, according to the stdlib documentation...
Now that's really weird: I'm trying to make my own short implementation with try-finally. Then, it shows me an inspection to change it to use. If I click I want to change it to use, it starts erroring.
e
what java are you targeting / what stdlib are you using
AutoCloseable.use() is in kotlin-stdlib-jdk7 as the interface isn't in java 6 (which is what the base kotlin-stdlib targets)
c
I've got this little thing only
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions.jvmTarget = "1.8"
}
in
build.gradle
I don't have
stdlib
set as a dependency, so I guess I have the base one?
e
hmm it should be picking the right one... what does
gradle dependencies
say?
c
Copy code
runtimeClasspath - Runtime classpath of compilation 'main' (target  (jvm)).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.4.20
|    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.20
|    \--- org.jetbrains:annotations:13.0 -> 16.0.1
...
Here are my plugins:
Copy code
plugins {
    id "application"
    id "org.jetbrains.kotlin.jvm" version "1.4.20"
    id "com.github.johnrengelman.shadow" version "6.1.0"
}
Don't know if it's needed, but here you go
e
adding/removing
kotlinOptions.jvmTarget = "1.8"
changes the stdlib dependency for me, not sure what's different for you…
c
Maybe that tasks.withType thing doesn't work?
e
you aren't explicitly mentioning stdlib in the dependencies block, are you?
c
No, I am not
Wait
e
because that will skip the automatic stdlib dependency
c
I must be blind, I would've sworn it's not there yet it apparently is
Well, that did indeed fix the problem, thanks a lot
Just in case you know something more than I do about Gradle or rather IntelliJ Idea:
Copy code
//noinspection GroovyAssignabilityCheck
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions.jvmTarget = "1.8"
}
Without the comment, Idea shows me a warning
Cannot infer argument types
, but Gradle builds everything without problems. Any way to fix it?
e
no clue, I use the Gradle Kotlin DSL 🙂
c
Okay then, thanks for the help anyway