Maven Multi Module Project Structuring Issues

后端 未结 3 2367
無奈伤痛
無奈伤痛 2021-02-20 05:31

Well here is an interesting experience i had since last couple of weeks structuring my maven multi module project.

When i decided to use maven for my build life cycle ma

相关标签:
3条回答
  • 2021-02-20 06:17

    This is a good question. There are many aspects that must be considered for a useful project layout. I'd like to try to answer one which you didn't mention. Is your app extensible by users? If it is, then consider creating a separate module for your public API layer (service interfaces, DTOs used by those services, and Exceptions thrown by the services).

    In our app, we have several maven modules per functional area. The idea is that a group worked on a feature within just one functional area and this isolation kept them messing with sources being modified by another group. Each functional area is broken down further in maven sub-modules we call "api", "domain", and "service" - we don't lump services/controllers, domain, and exceptions into a single module. The api module contains those classes we want to expose to customers for their customizations. Our service layer is the implementation of those interfaces. Further, we do not allow one module's service to call another module's service as this would bypass our service orchestration layer where customer can attach extensions to our services. Using separate maven modules per functional area helps enforce this.

    We have other modules (internal-api, web, adapter) but they don't really add to this topic.

    0 讨论(0)
  • 2021-02-20 06:29

    I figured out the issue. Controllers are presentation-layer components. The dispatcher expects the presentation layer components in the WEB-INF/classes folder in the target rather than looking for it in the lib. I am not sure if this is valid only for maven based structuring in eclipse. So finally these are the changes i have made

    a. Created a src/main/java source folder in web-app. It is not generated by default in web-app module. b. Add packages and respective controllers in the src/main/java folder.

    So the final structure that i have (i am not pasting exact eclipse snapshot, this is generalized view)

    Final Structure

    0 讨论(0)
  • 2021-02-20 06:30

    Its the way the eclipse render maven based project. It generally creates two structure. One based on master pom (parent project) and others based on individual module pom. however doing changes in any structure will reflect in the other one. As a practice I do changes in individual module folder structures and is more easy to read too.

    Personally I try to avoid multi-module projects as, if you're using the Maven Release Plugin, you are locked into releasing all your modules together.

    While this may sound like a convenience the problem arises when you need to do bug fix release to one of the modules - you end up releasing all the modules, not just the module with the bug fix, incrementing their version even though they haven't changed.

    You also take a hit if you're running CI with multi-module projects - you're build typically runs over all modules from you root pom but if you're working in a particular module, you end up taking the hit of building those that haven't changed, in effect losing some of the benefits that the modularization was meant to provide.

    So, go with independent modules but, and this is the important bit, create a common 'dependency' pom used by each.

    A 'dependency' pom is a pom that standardizes all the dependencies across your projects and is different in that those dependencies are specified in the dependencyManagement section rather than the dependencies section (it also sets up standard plugin config, etc). This allows your project poms to specify the dependency pom as their parent and then declare the dependencies they need minus the versions, which are picked up from the 'dependency' pom and thus standardized across your projects.

    If you are still concerned about being able to built everything, this can be achieved with a simple batch-file.

    0 讨论(0)
提交回复
热议问题