Maven继承和聚合

gro*_*rei 0 java inheritance aggregation maven

I'm just curious, what happens if there are used both inheritance and aggregation in the same maven application? This is the application structure:

my-project-app

  • my-project-jar
  • my-project-war

Now, in app's pom.xml, I declare jar and war projects as modules, and in the same time the the poms from both modules declare the app pom as their parent. It is create some kind of redundancy here, isn't it?

What is the best solution for this case?

xon*_*ned 5

It's not redundant. They do both different things.

If you define <modules> (aggregation) you just say, which projects have to built and it's package type is pom.

If you inherit you'll inherit the parent-pom's preferences by defining the <parent/>.

See:

继承和聚合创建了一个不错的动态特性,可以通过单个高级POM控制构建。您经常会看到既是父级又是聚合器的项目。例如,整个maven核心通过单个基本POM org.apache.maven:maven运行,因此可以通过单个命令mvn compile来构建Maven项目。但是,尽管两个POM项目,一个聚合器项目和一个父项目都不相同,所以不应混淆。一个POM项目可以继承(但不一定具有)它聚合的任何模块。相反,POM项目可能会聚合不从其继承的项目。

更多信息在这里