Maven uses

Time:2020-12-18

Dependency passing

  • In the dependency tree of engineering, the shallower the depth is, the more priority is given.
  • If two dependent packages are at the same level on the dependency tree, who is the first to choose the other
  • In summary, best practices for avoiding version problems when passing dependencies. In general, if the project directly depends on multiple modules of a certain framework, it is betterDeclare all of these dependencies

Module aggregation and inheritance

Maven polymerization

When there are many modules, you want to build multiple projects at a time instead of executing commands separately in the directory of multiple modules. Maven’s aggregation feature serves this requirement.

<parent>
    <groupId>com.ts.mall</groupId>
    <artifactId>ts-mall</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../mall-dependencies/pom.xml</relativePath>
</parent>

<artifactId>mall-dependencies</artifactId>
<! -- aggregation module must be POM, otherwise it cannot be built -- >
<packaging>pom</packaging>

<! -- modules is the core configuration to implement aggregation. Specify the module directory for Aggregation -- >
<modules>
    <module>../modules1</module>
    <module>../modules2</module>
    <module>../modules3</module>
</modules>

inherit

  • The grouopid and version of the child module are dependent on the parent module.
  • A module does not need to rely on the parent class of jar package, need to use Maven dependency management dependency management to solve this problem

summary

  • Aggregation is to facilitate rapid construction of projects
  • Inheritance is to eliminate duplicate configuration, which can simplify POM and promote the consistency of each module configuration.
  • The common point is that the packaging of the two modules is POM, and the parent module in the aggregation module and the inheritance relationship have no actual content except POM.

reference material
Maven practice (9) — module aggregation and inheritance

Recommended Today

DK7 switch’s support for string

Before JDK7, switch can only support byte, short, char, int or their corresponding encapsulation classes and enum types. After JDK7, switch supports string type. In the switch statement, the value of the expression cannot be null, otherwise NullPointerException will be thrown at runtime. Null cannot be used in the case clause, otherwise compilation errors will […]