maven notes

Posted by payjo on Fri, 17 Dec 2021 21:51:30 +0100

settings.xml
settings.xml location
  1. Label specifies the local save location of the local download dependency

${user.home}/.m2/repository means C: \ users \ username m2\settings. xml

  1. File | Settings | Build, Execution, Deployment | Build Tools | Maven's local repository in idea can be overwritten

settings.xml content

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

   <pluginGroups></pluginGroups>

   <proxies></proxies>

   <localRepository>.m2/repository</localRepository>

   <mirrors>
      <mirror>
         <id>settings-mirror</id>
         <url>https://maven.aliyun.com/repository/public</url>
         <mirrorOf>central</mirrorOf>
      </mirror>
   </mirrors>

 <profiles>
        <profile>
            <id>xxx-product</id>
            <repositories>
                <repository>
                    <id>xxx-xxx-repo</id>
                    <url>url</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            <repositories>
        </profile>
</settings>
Dependent download base priority
  1. All Maven projects reuse a local warehouse
  2. The central warehouse downloads the necessary builds from the remote warehouse / private server (configurable)

Local warehouse > mirror of specific warehouse repository mirror > warehouse repository configured in settings
Detailed priority: local repo > Settings profile repository > POM profile repository > POM repository > Central
Local warehouse > profile > remote warehouse and mirror > central Warehouse

Maven core concept
Relationship between warehouse address and coordinates
groupId com.huawei.xxxcommon.xxx
artifactid xxx-service 
version 1.0
packaging jar(bundle war...)
classifier Additional build information

groupid artifactid version Must be defined
 Warehouse address: base + com/huawei/xxcommon/dmq/xxx-service/1.0/xxx.jar
Maven dependency preference principle
  1. Relying on the shortest path first principle
    A-B-C-X{1.0} A-D-X{2.0} select X{2.0}
  2. The order of declaration in the pom file takes precedence over the dependencies declared first
  3. Override priority
    Dependencies declared in the child pom take precedence over the parent pom
maven lifecycle
  1. The three life cycles are independent of each other
    clean(pre-clean clean post-clean) > default(validate compile test package verify install deploy) > site
  2. In a set of life cycles, there are dependencies before and after the life cycle stages
  3. The mvn command points to the lifecycle phase
maven plugin
  • Maven itself is a framework, and the actual tasks are completed by plug-ins
  • The plug-in is bound to the life cycle stage. Users can implicitly execute tasks through the plug-in by specifying the life cycle stage
  • The packaging type controls the binding of the default life cycle to the plug-in goal
Meaning of common label
  • mirrorOf

Mirror the repository of a warehouse, fill in the repository id, * and match all warehouses
It is equivalent to an interceptor, which will intercept maven's requests for remote repository,
Redirect the remote repository address in the request to the address configured in the mirror

mirrorOf="*"  //Just now, after everything about mirror, the repository you configured doesn't work

mirrorOf=my-repo-id //Mirror my repo ID, the my repo ID warehouse you configured doesn't work

mirrorOf=*,!my-repo-id  //! It means non operation. Excluding the my repo ID warehouse you configured, other warehouses are mirrored
 Is to request a download my-repo-id Of the warehouse jar Not used mirror of url Download, others are used mirror Configured url download

mirrorOf=external:*  //If the local inventory exists, use the local library. If there are no downloads locally, use the url configured by mirror
  • packaging

Project release form: jar war rar POM Maven plugin ear EJB par

multi-moduls

maven 3 supports the multi module structure of maven project (aggregate project), which is usually composed of a parent module and several sub modules
The parent module must be packaged in pom and all child modules must be given in

  • relativePath

maven is looking for the parent module POM XML adds an additional search path

<parent>
    <groupId>com.company.department.group</groupId>
    <artifactId>reponame</artifactId>
    <version>xxx-SNAPSHOT</version>
    <relativePath>../../../pom.xml</relativePath>
</parent>

Topics: Maven