Question

In my project I have two modules (A,B) depend on common module C. I would like A,B share common configuration, such as repository configuration, plugin configuration, etc. In order to achieve this, C is made the parent pom and A,B inherit from it (no aggregation is required, so C does not reference A,B)

However, C by itself contains some java code, along with unit tests. Now, if I run mvn test inside C nothing is executed. Supposedly, pom-packaged modules should not include any code.

Is the above configuration terribly flawed? Should yet another common pom be introduced even though one already exists?

Was it helpful?

Solution

At very typical pattern in Maven projects is to have a module named "parent" which holds your common Maven-specific configuration, profiles, properties, dependency versions, etc. This is The Maven Way (TM).

The structure looks something like the following:

|-- parent
|-- common
|-- module-a
|-- module-b

So, common, module-a and module-b each depend on parent, and module-a and module-b depend on common.

See this excellent resource: http://www.sonatype.com/books/mvnex-book/reference/multimodule-web-spring.html

Note that "parent" can be a sibling of its child modules, in terms of directory structure. There is no requirement that the directory structure hierarchy match that of the modules.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top