Hello everyone! Is there a way to set the srcDir f...
# gradle
p
Hello everyone! Is there a way to set the srcDir for all sub directories of a directory in a generic way? To give an example, I have the following code:
Copy code
srcDir("src/routes/a")
srcDir("src/routes/a/asdf")
srcDir("src/routes/b")
srcDir("src/routes/c/xyz/zyx")
Right now, if I add a new directory under route, I have to add it also to my
build.gradle.kts
in the given snippet. Is there a way to accomplish that automatically, by adding all sub directories of
src/routes
? Thanks in advance!
j
I don't know if Gradle has something to do it automatically but you can use
FileWalkTree
to add every folder inside
src/routes
p
Hey Javier, thanks for answering! I actually tried that, but it looks like it's not picked up:
Copy code
File("src/routes/").walkTopDown()
        .filter { it.isDirectory }
        .map { it.canonicalPath }
        .map { it.removePrefix("/.../") }
        .forEach { srcDir(it) }
j
it is strange, I use it inside
settings.gradle.kts
to automatically
include
every module in the project
p
Hm, strange. I wrote a test for that which prints the directories and the resulting strings are all correct. After that I call srcDir on each of them, so no big magic involved there..
i
Doesn't
srcDir("src/routes")
include the files in all subdirectories recursively?