Any method that determines if a directory contains a Gradle project?


(Ross Goldberg) #1

Is there any method method that determines if a directory contains a Gradle project?

Does a directory contain a project if and only if it contains either a settings.gradle or a settings.gradle.kts? Are there any other requirements or options? e.g., are any other settings file names acceptable? Are any additional files required? Are any other (sets of) files sufficient?

It would be best if I could call some Gradle method to determine if a directory contains a project, since potential project indicators might change over time (e.g., settings.gradle.kts only became valid once the Kotlin DSL was released).


(Felix) #2

Is checking for existence/absence of build.gradle acceptable?
settings.gradle is applicable for multi-project builds only


(Ross Goldberg) #3

@feli74 Thanks for the suggestion.

After investigating a bit more, I think I probably should look for files matching the following regex:

(?:build|settings)\.gradle(\.kts)?

It looks like I could have a single-project with just build\.gradle(\.kts)?, or a multi-project with just settings\.gradle(\.kts)?.

I want to use this project auto-detection to automatically include projects in child directories of a specified folder, so I guess I’ll have to check if there’s any way of using other file names for build or settings files for an included project.

It would be much better if I could use a function from gradle itself to determine all this, since implementing it myself is extremely error-prone & brittle.

BTW, settings\.gradle(\.kts)? is only mandatory for a multi-project or a composite build, but is still applicable for single-project builds, too. In Gradle 5.0, nested builds will supposedly require a settings\.gradle(\.kts)?file, but I haven’t seen indications that they’ll be required for single-project builds.