Relative/absolute paths in gradle

I would really appreciate if someone could explain following behavior of gradle (7.2). With file() it works fine. Is File not supported in gradle’s task code anymore?

build.gradle:

task test {
    println(new File("build.gradle").exists())
    println(new File("build.gradle").absoluteFile.exists())
}

output:

$ gradle test

> Configure project :
true
false

> Task :test UP-TO-DATE

BUILD SUCCESSFUL in 1s