开发者

Reusing maven module as dependencies

I was hoping to be able to split my projects into Maven sub Modules, and reuse them as Maven dependency for other projects.

As I understand from the doc, the child modules must specify their parent project. This makes them unsuitable for reusing as dependencies.

This render the split in module far less attractive IMHO. Or am I missing something?

I tend to split projects in components when I need to sh开发者_如何学Pythonare them. Otherwise, why bother?

Can someone elaborate on that?

Is it possible to declare a module that do not specify it's parent? How can you refactor a dependency and all it's dependant projects if you cannot?

cheers


relativePath is just a hint at build time. Once all your modules and parent(s) are installed, you can refer to the individual modules as dependancies in your other projects.


As I understand from the doc, the child modules must specify their parent project. This makes them unsuitable for reusing as dependencies.

Specifying a parent project does not make a module unsuitable as a dependency. Most of the modules have a parent pom, which defines common dependencies/plugins and other things. Refer to spring dependencies, for instance.

Is it possible to declare a module that do not specify it's parent?

Each module is an individual maven project. As such it does not need a parent. Typically, in a hierarchical organization of modules, each module is in a folderand the parent pom is in the parent folder of the modules. The parent pom typically builds all the modules.

|
--- module 1
    |
    --- pom.xml
|
--- module 2
    |
    --- pom.xml
|
pom.xml <-- parent pom

In the absence of parent pom, you would need to build each module individually.

Refer to this SO discussion as well.


Parent poms, and pom project are useful, not doubt. But the doc says you have to specify the parent in a module. So if you want to reuse, say a server module of a project for another project, how can you do it?

|
--- server
     |
     --- pom.xml
|
--- client
     |
     --- pom.xml
|
--- webapp
     |
     --- pom.xml
|
--- Pom project 1
     |
     <modules>
        <module>../server
        <module>../client
|
--- Pom project 2
     |
     <modules>
        <module>../server
        <module>../webapp

With the above example, according to the doc, server project is supposed to specify pom project 1 as parent, and pom project 2 as well.

How do you handle a mix of modules and dependencies notion in such a case?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜