I'm slowly converting a bunch of files from groovy...
# community-support
c
I'm slowly converting a bunch of files from groovy to kts. One thing that has a bunch of conflicting information about it seemingly is how to take values from gradle.properties and reference them in a kts file. For example... in our settings.gradle we have some maven repositories declared that require a username and password. When I convert to settings.gradle.kts I can't reference those variables directly anymore. Can anyone confirm what the right way to reference a prop in gradle.properties (either in the project or global)? Essentially now I have
Copy code
awsRepoUrl=<https://1234567890.d.codeartifact.us-east-1.amazonaws.com/maven/my-repo/>
awsUsername=aws
awsPassword=eyJ0eXAiOiJKV1QiLCJh...
and
Copy code
maven {
  url = uri(awsRepoUrl)
  credentials {
    username = awsUsername
    password = awsPassword
  }
}
n
This should work:
Copy code
val awsUsername: String by settings
👆 1
😍 1
c
Didn't notice the small disclaimer about
by settings
I was trying
by project
with no luck. 🤦
e
it's of course also possible to
Copy code
val awsUsername = property("awsUsername") as String
or
findProperty()
if it's optional
when the property name is not a legal identifier, you can't use the
provideDelegate
(
by
) mechanism
v
No, there is no
findProperty
for settings, only for project. (Unless this has changed)
Neither am I aware of a
property(...)
method anywhere
e
v
There was some way to get it from settings even if delegation doesn't work because of the illegal characters, but I don't remember it right now. Should be somewhere on linen or the forums though 🙂
Ah, yes, you can since some versions do
providers.gradleProperty(...)
also in the settings script
c
sorry to bring this up again. but is it possible to use this similar syntax to get properties from local.properties?
you could define your own ValueSource which does, but there isn't one built in
c
Cool. I'll just tell my team to throw this one prop into their global gradle.properties and call it a day 😅