Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////settings.gradle.kts
- storeInGradleExtras(includeAllSubdirectories("avito-app"))
- /**
- * @return module's paths that was included
- */
- fun includeAllSubdirectories(dir: String): ModulePaths {
- val paths = HashSet<String>()
- file(dir).listFiles()
- .filter { file -> file.isDirectory && (file.name != "build") }
- .forEach { currentFolder ->
- if (isGradleModuleDir(currentFolder)) {
- val path = ":${dir.replace('/', ':')}:${currentFolder.name}"
- paths.add(path)
- include(path)
- } else {
- paths.addAll(includeAllSubdirectories("$dir/${currentFolder.name}").paths)
- }
- }
- return ModulePaths(directory = dir, paths = paths)
- }
- data class ModulePaths(val directory: String, val paths: Set<String>)
- /**
- * Will be used in build scripts in modules.
- * See `modulesGroup` function usages.
- */
- fun storeInGradleExtras(paths: ModulePaths) {
- (gradle as ExtensionAware).extensions.extraProperties.set(paths.directory, paths.paths)
- }
- fun isGradleModuleDir(folder: File): Boolean {
- return hasFile(folder, "build.gradle") || hasFile(folder, "build.gradle.kts")
- }
- fun hasFile(folder: File, fileName: String): Boolean {
- val file = File(folder, fileName)
- return file.exists() && file.isFile
- }
- //// build.gradle.kts
- dependencies{
- gradle.modulesGroup("avito-test").forEach { modulePath -> androidTestImplementation(project(modulePath)) }
- ///
- fun Gradle.modulesGroup(name: String): Set<String> {
- @Suppress("UNCHECKED_CAST")
- val modules = (this as ExtensionAware).extensions.extraProperties[name] as? Set<String>
- if (modules == null) {
- throw IllegalStateException(
- "Trying to access modules group, named: $name\n" +
- "it should contain set of module names but it's not\n" +
- "Check settings.gradle or settings plugins where it should be set"
- )
- } else {
- return modules
- }
- }
Add Comment
Please, Sign In to add comment