Is it a known issue that `ReplaceWith` deprecated ...
# gradle
m
Is it a known issue that
ReplaceWith
deprecated substitutions are not working in
build.gradle.kts
? Trying to migrate to Gradle 8.3 that deprecates
project.buildDir
, I can't get the quick fix to work
j
you mean Gradle 8.3?
๐ŸŽฏ 1
Didnโ€™t know
buildDir
was going to be deprecated
m
Uhuhu yea sorry ๐Ÿ˜… Don't want to look at Gradle 3 ๐Ÿ™ˆ
Maybe it's just the Kotlin helper
v
๐Ÿฅด
๐Ÿ˜„ 1
m
Ah nope, it's also deprecated in
Project
v
Is
ReplaceWith
a thing in Java?
m
I don't think so
But it is in Kotlin!
Tangential but I believe the non-working for me
ReplaceWith
is also slightly unexact, filed this
v
Probably, yes, I prefer to read`layout.buildDirectory.get().asFile` though. :-D
๐Ÿ˜ƒ 1
j
I have found very hard to deal with directory and file properties APIs, I would like that Provider<File> to be a reality
m
Same, I usually
asFile
my way until I get something that compiles ๐Ÿ˜…
I guess
Path
is the new
File
though ๐Ÿคท
v
You can use
Provider<File>
it is just not as expressive, as it is unclear whether it is a file or directory.
๐Ÿ‘ 1
Same for
Path
, but yeah,
Path
is preferable over
File
in most cases too
j
I have got crashes with that some times, and the crash indicates I should use FilePropery or whatever
v
But regarding the replacewith, even in a
.kt
file I do not get the a quick-fix to replace
๐Ÿ‘€ 1
m
Mmm that's weird...
v
image.png
Maybe it is because the definition of the method is in the Java interface
m
Same here actually
Maybe it is because the definition of the method is in the Java interface
Ah yes, in a plain .kt file, it uses the
Project.java
API directly
v
Also, the whole
ProjectDelegate
is also declared deprecated o_O
๐Ÿ˜ฎ 1
Ah yes, in a plain .kt file, it uses the
Project.java
API directly
That's why I casted
target
to
ProjectDelegate
, so it does not use
Project
๐Ÿ‘ 1
If I navigate to
buildDir
I land in
ProjectDelegate
๐Ÿ‘ 1
m
Gotcha, didn't see this
Oh well..
Removing
ProjectDelegate
seems reasonable to me. Putting it back in scope is a simple
project.apply {}
and it makes everything more explicit (and avoids accidentally resolving
name
to the wrong receiver)
Usages of
ProjectDelegate
do not show any warning though...
Since it's all implicit I guess?
v
Probably
Ah, in
ProjectDelegate
you have
fun getBuildDir()
. So if you do
getBuildDir()
, you get the replacement quick-fix also in kts file
๐Ÿ‘€ 1
m
Copy code
'Build_gradle' is deprecated. Will be removed in Gradle 9.0
It's all going away ๐Ÿ˜„
v
If you have
fun getBuildDir()
in a Kotlin file, you cannot use
buildDir
naturally
You need a property in Kotlin
The getter-magic only works with Java interop
I wonder that navigation goes to
ProjectDelegate
method actually now
I guess this might be a bug in KTIJ actually, that it does not show the replacement quick-fix from the overridden
getBuildDir()
At least worth a try to report it as bug
m
Using
getBuildDir()
gets me a step closer fails for me in that specific case because it replaces with
this.layout.buildDirectory.get()
but
this
is not the
ProjectDelegate
v
Yeah, that seems to be another bug in the quick-fix implementation
m
The getter-magic only works with Java interop
Not sure I follow, how come I can write this in Kotlin if there is no Java involved ๐Ÿค”
Copy code
// calls ProjectDelegate.getBuildDir() under the hood
buildDir
v
Java is involved
ProjectDelegate
implements
Project
m
Ahhhh gotcha
v
So the
getBuildDir
is defined by Java and thus can be used with
buildDir
๐Ÿ‘ 1
Are you going to report these two bugs to KTIJ? ๐Ÿ™‚
m
I have one: โ€ข does not show the replacement quick-fix from the overridden
getBuildDir()
Not sure about the second
v
The second is the one about the wrong receiver (using
this.
when it shouldn't while replacing)
m
Ah yes!
I'll open those ๐Ÿ‘
๐Ÿ‘Œ 1
Second one, I can't get even simple replacement to work blob thinking fast .
It's just removing everything sad panda . What do I miss?
Copy code
@Deprecated("Deprecated", ReplaceWith("helloo"))
fun hello() {
    println("hello")
}

fun helloo() {
    println("helloo")
}

fun main() {
    hello()
}
v
A 3rd bug I'd say. If you do
ReplaceWith("helloo()")
it works
๐Ÿ‘ 1
m