Kotline vs Groovy gradle.properties.kts vs gradle.properties

I have searched StackOverFlow and Google for to long. This has to be simple. Try to be a good programmer and switch over to Kotlin from Groovy. :neutral_face:

Groovy
gradle.properties file

Username=Dummy

build.gradle
username = "${Username}"

Kotlin

gradle.properties.kts file

Username=Dummy

build.gradle.kts

username = project.properties("Username").toString()    //Working  

HOWEVER in setting.gradle.kts

username = project.properties("Username").toString()    //Not working getting

> Function invocation 'project(...)' expected

Try to be a good programmer and switch over to Kotlin from Groovy.

:ok_hand:
While, you can as well use Groovy DSL, that’s fine.
You just hurt yourself by doing so. :slight_smile:

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