How to create a maven module of a child module with a parent module?

I have several modules in my project, and they depend on each other both directly and transitively. When I create "Project A", where "Project D" is automatically created.

Project A > Project B > Project C > Project D where > means Project B depends on Project A 

"Project D" pom snipeet:

 <project xmlns="..."> <modelVersion>4.0.0</modelVersion> <groupId>com.myProduct</groupId> <artifactId>build-MyProjectD</artifactId> <name>MyProjectD</name> ........ </project> 

Since the building “Project A” automatically creates “Project B”, in my understanding, for this to happen somewhere, build-MyProjectD should be added as a dependency in one of these projects Project A > Project B > Project C , but I don’t found links to the build-MyProjectD under the poses of these projects.

Any idea how there is another way to create a child module (in this case, "Project D") without having a child artifactId in the upstream project?

+6
source share
2 answers

You need to create an aggregator project. See the link for more information on the concept of aggregation .

Basically, you create a parent project containing several “modules”. When a parent is created, modules are also automatically created.

If you declare dependencies between modules, Maven will automatically build the different modules in the correct order, so if "Project A" depends on "Project B", first "Project B" is created, and then "Project A" so that its artifact is available for creating a second artifact.

See also this question from the Maven FAQ .

+14
source

For the parent project, Maven will build all the child modules when creating the parent project. Add modules to the parent pom. Assuming A is your parent project

  <modules> <module>projectB</module> <module>projectC</module> <module>projectD</module> </modules> 

and in modules (B, C and D) add project A as a parent (this is optional, thanks @Guillaume Polet )

  <parent> <groupId>foo.bar</groupId> <artifactId>ProjectA</artifactId> <version>1.0-SNAPSHOT</version> </parent> 

So, if you create projectA, it will build ProjectB, ProjectC and ProjectD. Also maven is smart enough to determine the correct build order for B, C, and D.

+6
source

Source: https://habr.com/ru/post/980257/


All Articles