Hey everyone! How can I access the instance of pr...
# gradle
n
Hey everyone! How can I access the instance of project in
settings.gradle.kts
? I couldn’t find one(
project
) of what I have in root
build.gradle.kts
1
t
AFAIK you could not access it, the closest what you could access is
ProjectDescriptor
n
I see, thanks. We have a custom properties file in which developers have their own PAT for some repositories. We omit that file in git. Is there any way to read a custom properties file in Settings?
v
Why do you actually want to access the project? It is possible in a delayed way, but my guess is, that you do not actually want / need it.
t
Is there any way to read a custom properties file in Settings?
You could, like a normal properties file
v
For what would you have needed the project for that?
t
For example:
Copy code
File versionPropertiesFile = new File(rootProject.projectDir.parentFile, "gradle/versions.properties")
def versionProperties = new Properties()
versionPropertiesFile.withInputStream {
    versionProperties.load(it)
}
v
Btw. just in case you are interested, it would have been for example
Copy code
gradle.rootProject { 
    // do action as soon as project is available, which is after settings evaluation
}
to access the root project, but as I said, just in a delayed fashion.
👍 1
Why
rootProject.projectDir
? Why not
settingsDir
?
t
yeah,
settingsDir
will also work
v
Well, as long as the settings script is in the root project dir at least
t
hm, accessing
Project
via
gradle
- nice 👍
v
But if not, the settings script writer would know as he would have changed that fact.
t
ah yeah, I've copied this from
buildSrc/settings.gradle
- in this case it should be
rootProject
n
Thanks to both of you! I’ve fixed it 🙂
a
I'm a bit late, but my preference for this is to put settings into
$GRADLE_HOME_DIR/gradle.properties
and load them using Gradle providers using
providers.gradleProperty("artifactory_password")
can be overridden using environment variables too https://stackoverflow.com/a/72075210/4161471
n
wow that sounds really cool. So one can put their secrets in global
gradle.properties
and one line code is enough to retrieve it right?
👌 1
a
yes - also you can override it with a command line arg, or a environment variable (very useful for build servers). Also it's a provider so it's only evaluated if & when it's needed
n
yes! thanks for the heads-up! Will definitely look into this
👍 1