Last active
November 14, 2022 22:09
-
-
Save bgogetap/c1610fbb4f83e2953b541b838c47e62a to your computer and use it in GitHub Desktop.
Snippet to add to settings.gradle.kts to auto-add any gradle module (no more explicit Include(":mymodule") )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val modules = mutableSetOf<String>() | |
val ignoredDirectories = setOf("build", "buildSrc", "gradle", ".idea") | |
fun fillModules(files: List<File>, targetPath: String) { | |
files.forEach { file -> | |
if (file.isFile) { | |
if (file.name == "build.gradle" || file.name == "build.gradle.kts") { | |
modules.add(targetPath) | |
} | |
} else { | |
if (ignoredDirectories.contains(file.name)) { | |
return@forEach | |
} | |
val updatedParentPath = "$targetPath:${file.name}" | |
val childFiles = | |
file.listFiles()?.filter { it.isDirectory || it.name.contains(".gradle") } | |
if (childFiles != null) { | |
fillModules(childFiles, updatedParentPath) | |
} | |
} | |
} | |
} | |
val projectDirectories = checkNotNull( | |
rootProject.projectDir.listFiles() | |
?.filter { it.isDirectory } | |
) { "No directories in project" } | |
fillModules( | |
files = projectDirectories, targetPath = "" | |
) | |
modules.forEach { include(it) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment