This message was deleted.
# community-support
s
This message was deleted.
a
Assuming you’re using the Kotlin DSL, can you try fetching it dynamically using this?
Copy code
// settings.gradle.kts

val rootGradle: Gradle = generateSequence(gradle) { it.parent }.last()
val projectsRootDir: File = rootGradle.rootProject.projectDir
It will recursively fetch the root gradle instance, and
generateSequence()
will stop when the parent is
null
. I thought it up a while a go, but I haven’t had a chance to use it in anger so I’m curious if it works!
Never mind! I get an error
Copy code
Settings file '/projects/my-gradle-project/settings.gradle.kts' line: 22
The root project is not yet available for build.
I’m sure I had fetching the root dir working at some point. Maybe it was this? 🤔
Copy code
// settings.gradle.kts

val rootGradle: Gradle = generateSequence(gradle) { it.parent }.last()
val projectsRootDir: File = rootGradle.startParameter.currentDir
g
hey, thanks for chiming in! 🙂 so the problem is that there isn't really a single "root project" - as the dependency graph in the monorepo looks more like a forest instead of a single tree with a single root - each service is it's own separate build that drags in shared code through
includeBuild
statements. there are still some straightforward solutions on how to find the right directory, the bigger question is how not to duplicate that code for each project's settings file... groovy builds are easy - I just calculate the thing in the init script, and add it to the extensions. however in kotlin dsl this seems to be an impossible task for some reason?
v
Just access it in the settings script the "stringy" way? It is there to be used, you just don't get typesafe accessors generated in settings scripts.
g
yeah, i think i will go ahead with something like that. i would have just preferred though if i can actually have a typesafe solution, and it didn't seem like it should be a problem...
v
Have the variable as property in an extension you add. Then you can get the extension by type and use it. It would be type-safe, just not as convenient as the generated accessors.