1

I currently work on a project which comprises approximately a dozen sub-projects.

Each sub-project contains a POM which builds the dependency seperately.

Upstream sub-projects include the downstream sub-projects as dependencies in the same way that you would include a dependency on something like log4j:

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>

We hold these dependencies in a local Nexus repository.

This seems to work for us.

However I have today, after 11 months of development, decided to revisit these dozen POM files with refactoring in mind.

I have subsequently discovered the <parent> and <module> tags and am starting to question if my Maven project strategy is 'right'.

What benefit would there be to refactoring my POMs such that the upper-most level POM (a Web WAR project) is changed into a Parent POM which lists modules rather than a series of dependencies as above?

I would I anticipate most of the dozen sub-projects to take on a lifecycle in their own right, such that they would be available within the company's Nexus repository as code libraries for other company projects.

For example, is it the case that one uses a multi-module approach to break up and organize the composition of a sub-component of a project? Or would one take a module to represent an entire component of a project?

3
  • 1
    I thought the convention is all non-leaf module should use abstract packaging type POM. I don't know if your strategy is right or wrong, but it is definitely not the convention based on my experience.
    – yorkw
    Dec 4, 2012 at 1:39
  • Thanks for your suggestion @yorkw. I have continued to read around the subject and, in addition to your comments, the key thing I have identified is that, in the case of Project Aggregation, a Maven module specifies a single dependency as its parent. To borrow a term from UML, for 'composition', this is fine, but if a dependency could be used by many 'parents'/could take on a lifecycle of its own, perhaps my existing approach (to make it a standalone dependency available from a repository) is more 'correct'. I expect the 'correct' answer is actually a combination of both!
    – 8bitjunkie
    Dec 4, 2012 at 9:48
  • 1
    Only one question: Should the sub-projects be released with the same version or to the same point of time?
    – khmarbaise
    Dec 4, 2012 at 12:58

1 Answer 1

0

Thanks for everyone's views so far - I realise this question is subjective.

After a while it seemed to me that the 'right' answer to this question would be determined by another question: Do each of the subprojects take on a lifecycle of their own?

I suppose we could use UML class aggregation and composition as a metaphor. If a subproject (leaf node to borrow a term from @yorkw) cannot exist on its own or have a lifecycle of its own outside the scope of the parent project (be that a WAR, an EAR, whatever) then I would say IMHO that the structure would warrant the use of modules in a parent POM.

Otherwise, since the project can stand on its own two feet, I would say (again IMHO) that the structure would warrant an inclusion of this project as a dependency on its parent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.