Last active
October 23, 2022 07:06
-
-
Save efemoney/9eeeefd95dbf081026e1d6a88a924827 to your computer and use it in GitHub Desktop.
Gradle Settings script/code that allows you to have any (*matching*) directory structure for your gradle modules
This file contains hidden or 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 ProjectDescriptor.descendants: Sequence<ProjectDescriptor> | |
get() = children.asSequence().flatMap { sequenceOf(it) + it.descendants } | |
gradle.settingsEvaluated { | |
rootProject.descendants.forEach { | |
// Given path - :tooling:idea-plugin OR :tooling-idea-plugin | |
val path = it.path | |
// after splitting - [tooling, idea, plugin] | |
val splitPath = path.trim(':').replace(':', '-').split('-') | |
// path candidates - /tooling/idea/plugin, /tooling/idea-plugin, /tooling-idea-plugin | |
val filePathCandidates = generateSequence(splitPath) { | |
if (it.size <= 1) null else it.dropLast(2) + it.takeLast(2).joinToString("-") | |
} | |
// first directory that exists becomes project path | |
// todo: maybe first directory with a build.gradle.kts?? 🤔 | |
filePathCandidates | |
.map { file(it.joinToString(File.separator)) } | |
.firstOrNull(File::isDirectory) | |
?.let { project(path).projectDir = it } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment