I have a question about Gradle sourceSets. I am tr...
# gradle
m
I have a question about Gradle sourceSets. I am trying to find a good way to apply DDD patterns in my project, and I was thinking about how to encapsulate the different layers. My goal is to use the model where the domain code is on its own with zero dependencies except for stdlib, coroutines, and logging. Application layer depends on the domain code but also has almost zero external dependencies. And infra layer depends on both domain and application layers, and is what deals with talking to databases, message brokers, etc., so it has a number of those dependencies. So I was thinking that maybe I could use a single jar for a given application module (mapped to a bounded context). It would have a sourceSet each for the domain, application, and infrastrucuture layers, with the dependencies between them as described above. Code marked as
internal
in each layer should only be visible to other code in that layer (and its corresponding test sourceSet). Code outside of the module (jar) should only be able to see public code in the infrastructure layer. That is what comprises the public API for the whole jar file, and it is tiny. Just a couple of extension functions, interfaces, and classes. The compilation should result in only a single jar file. Is that something I can get working with sourceSets? Would JPMS modules be a better fit? I've never played around with JPMS, and I'm still learning Gradle. I know I can mostly achieve this by just extracting the layers into their own projects, but then it's hard to enforce the encapsulation because other projects can simply declare a dependency on those. I considered using a composite build but then I can't share dependencies or convention plugins between the components. We aren't a huge team, so it wouldn't be the end of the world, but if I can come up with a better solution then that would be ... better! Thanks a lot, Morgan
👀 1