https://kotlinlang.org logo
Title
p

Philipp Mayer

10/05/2020, 3:44 PM
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:
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

Javier

10/05/2020, 4:01 PM
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

Philipp Mayer

10/05/2020, 4:15 PM
Hey Javier, thanks for answering! I actually tried that, but it looks like it's not picked up:
File("src/routes/").walkTopDown()
        .filter { it.isDirectory }
        .map { it.canonicalPath }
        .map { it.removePrefix("/.../") }
        .forEach { srcDir(it) }
j

Javier

10/05/2020, 4:22 PM
it is strange, I use it inside
settings.gradle.kts
to automatically
include
every module in the project
p

Philipp Mayer

10/05/2020, 4:29 PM
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

ilya.gorbunov

10/06/2020, 8:56 PM
Doesn't
srcDir("src/routes")
include the files in all subdirectories recursively?