I am building a library which has a few demo projects, and will have a huge load of examples projects. I am currently including them manually one by one in the settings.gradle file, but I expect to have over 100 examples.
So I am wondering if there was a way to include all subprojects under the example folders without manually specifying them one by one in the settings.gradle.
Another side effect is that the example folder itself gets built even if there is no code inside. Is there a way to exclude that folder or it does not really matter if it does get built?
Here is the directory structure of the project (2 level depth):
I get your logic but unfortunately even after reading a bit about collections, I cannot make it works. If I add the code βas isβ and remove any include in my settings.gradle file, I get the following error.
* What went wrong:
Could not compile settings file '/mnt/data/git/javalib_blackbook/settings.gradle'.
> startup failed:
settings file '/mnt/data/git/javalib_blackbook/settings.gradle': 2: unexpected token: . @ line 2, column 10.
new File(.).listFiles().each
^
So the problem was the dot in the parenthesis, so I thought maybe it was lacking apostrophes around the dot since it should be a directory path expressed as a string. So I replaced it with File(β.β) and now I got the following message:
* What went wrong:
A problem occurred evaluating settings 'javalib_blackbook'.
> Could not find method include() for arguments [./blackbook_demo] on settings 'javalib_blackbook' of type org.gradle.initialization.DefaultSettings.
From what I can see, it tries to include β./blackbook_demoβ instead of β:blackbook_demoβ. Maybe that is the problem, I need to substitute the β./β for β:β.
I had an issue where the demo was dependent on the terminal. Since the the terminal appears alphabetically afterwards, it could not find the dependency. So I used portions of your code to create new code that will only explore the examples folder instead. Here is the new settings file which seems to work so far.
rootProject.name = 'javalib_blackbook'
include ":blackbook_terminal", ":blackbook_demo"
new File("examples/").listFiles().each
{
if (it.directory && new File(it, 'build.gradle').exists())
{
include ":${it.name}"
}
}