Use of Maven (dependency conflict)

1.1Maven coordinate

Coordinates: each jar package or maven project has a unique ID card on the network

Coordinates (GAV)

  1. Reverse order of groupId company or organization domain name (warehouse: package name)
  2. artifactId project name or module name (warehouse: project name)
  3. Version version number (warehouse: version number)

Is the coordinate related to the local warehouse?

  • It matters.
  • Path: / warehouse name / groupid name / artifact name / version/

1.2 Maven common commands

  • Compile: compile. Compile Java files in the project into class files, and generate target directory
  • clean: clear. Delete target directory
  • Package: package. Package the contents of target directory into jar or war
  • Install: install. Install the generated jar package or war package to the local warehouse
  • All local projects can share their methods and classes

1.3 POM label details

<!-- projectLabels: parent labels ,FuturepomAll content inprojectInside the label-->

<project xmlns="" xmlns:xsi=""


  <!-- Version No -->



    groupId+artifactId+version:Global unique, coordinate, abbreviationGAV


    <!-- groupid: Package name -->   


  <!-- Project name -->


  <!-- Version number, version number of the current project -->


  <!-- Packing method  

jar: javaSEproject


pom: Parent project (multi module explanation)-->


  <!-- nameandurl: Optional assignment -->   



  <!-- properties:Attribute, which can be configured with many attributes. This label is not required -->  


    <!-- Encoding is configured by default -->





  <!-- dependencies:Complex number, which can be used to place multiple -->


    <!-- dependency:Singular, specificjarpackage -->









    <!-- plugins:Plug-in unit-->


        <!-- plugin:Specific plug-ins -->


            <!-- UnifiedjdkVersion of plug-in, mandatory addition -->












1.4 add custom dependency for POM

  • Local warehouse: (normal use of disconnected network)


  1. Network:

Local warehouse import: it is applicable to know a class name under the project name / jar package name / jar package. The jar package must exist in the local warehouse

Network import: applicable to jar package not in local warehouse

1.5 scope of dependence

  • Different jar packages have their own scope of action, in order to use jar packages more accurately.
  • Dependency scope: jar package scope

2. Dependency conflict

2.1 dependency conflict

In the future, the project will crash due to different versions of the same jar package.

  • jar package dependency in Maven project:

Direct dependence: A depends on B

Project A, directly imported the jar package B

  • Indirect dependence (transitive dependence): A depends on B, B depends on C, A indirectly depends on C

Project A directly imports jar package B, which depends on jar package C, while project A indirectly depends on jar package C

Dependency conflict is caused by indirect dependency

  • Project A directly imports jar package B and jar package C
  • Jar package B relies on jar package D version 1.1
  • Jar package C relies on jar package D version 2.1

2.2 mediation principle depending on Conflict: priority for those who are close to the path

Path closest direct dependency

2.3 mediation principle relying on Conflict: the first statement takes precedence

  • Which indirect dependency is declared first will be imported according to its version

2.4 dependency conflict resolution: direct exclusion

It is recommended to exclude leaf nodes, otherwise it is easy to cause chain reaction

3.1 engineering stratification

Dao domain service web utils commons subproject

3.2 aggregation (multi module) and inheritance

  • Inheritance: in maven project, child project can inherit the dependency and plug-in configuration of parent project.
  • Aggregation: multiple maven subprojects can form a complete project, which is aggregation

  • Inheritance: child projects inherit parent project dependencies and plug-ins
  • Aggregation: the subprojects depend on each other to form a whole. The whole is an aggregation project. Aggregation and inheritance are usually used together

Tags: Programming Maven Apache network Java

Posted on Thu, 07 May 2020 08:10:28 -0400 by graham