Slackbot
07/25/2023, 8:42 AMAdam
07/25/2023, 8:49 AMdata
as a project, unless you’re using allprojects {}
or subprojects {}
?Stylianos Gakis
07/25/2023, 8:55 AMapp
|-app
|
|-notification (shouldn't be a module, just a dir)
|-|-foo (a gradle module)
|-|-bar (a gradle module)
|
|-notification-badge-data (a gradle module)
And sometimes idk if it’s gradle, or my IDE or whatever but I either get warnings in the IDE, sometimes I can’t build and gradle errors with
Cannot find module entity for 'Module: 'app:notification-badge-data:main'.
And stuff like that. Don’t have the error in front of me now to properly copy paste just doing it from memory.
So I thought maybe if I don’t get these intermediate empty modules gradle would stop complaining about stuff like thisAdam
07/25/2023, 8:56 AMAdam
07/25/2023, 9:00 AMbuild.gradle(.kts)
file with group = "com.foo.blah"
, but the module name is inferred by the subproject directory.
So if you have multiple subprojects like so…
└── app/
├── notification-badge-data/
│ └── main
├── prime-database/
│ └── main
└── x-components/
└── main
and they all have the same group of com.foo.blah
, then Gradle is going to get confused, because com.foo.blah:main
could refer to any one of three subprojects…Adam
07/25/2023, 9:01 AMStylianos Gakis
07/25/2023, 9:05 AM:bar
:bar:foo
And see if that helps 👀
Thanks a lot for helping out btw 🙏 Super appreciated.Adam
07/25/2023, 9:05 AMAdam
07/25/2023, 9:08 AMAdam
07/25/2023, 9:10 AM.
└── modules/
├── core-app
├── notifications-foo
├── notifications-bar
└── notifications-badge-data
Stylianos Gakis
07/25/2023, 9:11 AMStylianos Gakis
07/25/2023, 9:11 AMnotifications
directory only, to bundle up the gradle modules has improved navigating our gradle modules by a lot. I just don’t like that it’s fighting me sometimes when I don’t know what I’m doing 😅Stylianos Gakis
07/25/2023, 9:13 AM-
to split modules, don’t do yet another nesting layer with any :
in there (after :login-strategy).Stylianos Gakis
07/25/2023, 9:14 AM:feature:foo-bar
where foo-bar
is all those alternatives is probably the way to go hereStylianos Gakis
07/25/2023, 9:15 AMlogin-strategy
not be a gradle module (if it is right now as I suspect), and if that matters or not (I would guess it does at least a little bit for configuration time etc) so if someone has more thoughts on it, like if I really shouldn’t care, of how to actually do it I’d love to hear about it!Adam
07/25/2023, 9:27 AMI would guess it does at least a little bit for configuration time etcI suspect an empty subproject wouldn’t be measurable, since there’s no build script or plugins to run. Unless a project uses `allprojects {}`/`subprojects {}`, which would add configuration.
Adam
07/25/2023, 9:34 AM// buildSrc/src/main/kotlin/my-base-convention.gradle.kts
// append the path (e.g. `:feature:foo-bar`)
group = "com.foo${project.path.replace(org.gradle.util.Path.SEPARATOR, ".")}"
Vampire
07/25/2023, 1:21 PMinclude("foo:bar")
will create foo and bar. Just do include("bar")
and then set the project directory of that project how you want itStylianos Gakis
07/25/2023, 2:17 PMinclude("test")
project("test").projectDir = file("feature/login-strategy")
or something like that.Stylianos Gakis
07/25/2023, 3:13 PMval File.gradleModuleDescendants: Sequence<File>
get() = listFiles()
?.asSequence()
?.filter {
it.isDirectory
}
?.flatMap {
if (File(it, "build.gradle.kts").exists()) {
sequenceOf(it)
} else {
it.gradleModuleDescendants
}
} ?: emptySequence()
rootProject
.projectDir
.gradleModuleDescendants
.forEach { file ->
include(file.name)
project(":${file.name}").projectDir = file
}
Which seems to find the right directories, now I guess the only issue is with duplicate names of modules, since I am not getting any proper generated type-safe accessors, nothing gets generated.Vampire
07/25/2023, 7:13 PM./gradlew projects
now give the expected list? If so, accessors in the build scripts should just work fine.Stylianos Gakis
07/26/2023, 3:17 PM./gradlew projects
returns the right list, and then accessors just as you said worked perfectly fine. Now no need to do projects.path.to.module
, it is just projects.moduleName
which is what I was getting wrong before.
The only tiny annoying thing that exists now is that in the IDE, it’s trying to tell me that despite the fact that the directory is called “apollo-core” for example, this is actually the “hedvigandroid.apollo-core” as far as gradle is concerned. Where “hedvigandroid” is just the root directory name of my project.
Don’t know how I would get rid of that, but this is very good progress. And my snippet here did actually work 👌Vampire
07/26/2023, 3:48 PMStylianos Gakis
07/26/2023, 3:52 PM