Maven - making child projects that can be independent of their parent

后端 未结 5 856
一生所求
一生所求 2020-12-23 17:01

I\'m a bit of a Maven newb, and I\'m trying to setup a maven project that builds several child projects, but still allows someone to just grab one of the child projects and

5条回答
  •  旧时难觅i
    2020-12-23 17:42

    You have to take care of the differences between the parent-child relation and the aggregation concept in Maven2. They are not the same principle, even if they are really often used at the same time.

    PARENT

    The first concept is that a project declares in his pom.xml a parent:

    
        4.0.0
        
            foo
            bar
            42
        
        ...
    

    In this case, in order to build this component, the parent project must be found in the local repository. This is your case here.

    The interest of the parent concept in Maven 2 is to inherit properties, dependencies, configuration. This is the place where you will put all the common information of the children projects.

    This is the exact same concept of the extends in Java language.

    AGGREGATION

    In this case, you have a project that aggregates several sub modules by specifying their names in module nodes:

    
        commons
        client
        server
        ...
    
    

    This means that every command that you will run on this root project will be executed on each module (the order is defined by the Maven 2 Reactor). For example, if you run mvn clean install on the root project, Maven 2 will run this command on the root project, then on project commons, then on client and finally on server.

    In this concept, you are able to compile one project without compiling any other one project (except if there are inter-dependencies of course).

    Here is a schema that shows the two different concepts:

    You have a more detailed explanations on these two concepts in the Maven : The Definitive Guide, here.

提交回复
热议问题