Try to be a good programmer and switch over to Kotlin from Groovy.
While, you can as well use Groovy DSL, that’s fine.
You just hurt yourself by doing so.
gradle.properties is a Properties file, not a Groovy DSL file.
So there is no such thing as a gradle.properties.kts file, even when using Kotlin DSL Gradle scripts, the properties file stays the same.
Thus your “working” probably just means it compiles, but sets the username to null.
That the last snippet not works is obvious, isn’t it?
You are in the settings script.
In the settings script you define which projects are part of the build.
So you cannot access any projects’ API in that phase of course.
Actually, it should be
val Username: String by project
username = Username
and
val Username: String by settings
username = Username