"0" README
1) Part of this text is transferred from "Maven Combat" to review
"maven (6) warehouse" related knowledge;
"1" What is Maven warehouse
1) Intro to widget: in Maven, any dependency, plug-in, or project-built output can be called artifacts, and any one component is uniquely identified by a set of coordinates;
(dry-component definition)
2) Warehouse: Thanks to the coordinate mechanism, any MAVEN project uses any one component in the same way. Based on this, MAVEN can store all the artifacts shared by the MAVEN project in a single location, and this unified location is the warehouse;
(dry-warehouse definition)
layout of the "2" warehouse
1) The layout of the warehouse: any component has its own unique coordinates, according to which can define the unique storage path in its warehouse, this is the way Maven warehouse layout;
(Dry-warehouse Layout method definition)
2) correspondence between paths and coordinates: for groupid/artifactid/artifactid-version.packaging;
3) interested in children's shoes, you can look at the source of Maven, how it generates the path in the warehouse according to the component information (in fact, it is a process of intercepting strings and stitching strings, and Tomcat parsing the request path is the same reason)
Classification of "3" warehouses
1) Warehouses are divided into two categories: local warehouses and remote warehouses;
2) Maven Search Widget method: when Maven looks for a widget based on coordinates, it first looks at the local repository, and if there is one in the local repository, it is used directly; if not, or if you need to see if there is an updated build, MAVEN will go The remote repository is found; After the build is discovered, it is downloaded to the local repository for reuse;
3) Private server: is another special remote warehouse, in order to save bandwidth and time, should be set up in the LAN a private warehouse server, with its proxy all the external remote warehouse, and the internal project can be deployed to a total of other project use;
(Dry goods-definition of a)
Attention)
< Strong>a
1) except for the Central warehouse ( http ://repo1.maven.org/maven2/ http://download.java.net/maven/2&NBSP; http://repository.jboss.com/maven/2 The
A2) Maven repositories are categorized as follows:
/strong>
"3.1" Local warehouse
1) Intro: The default case, each user in their own user directory has a path named ~/.me/repository warehouse directory;
2) Custom local warehouse directory address: You can edit the settings.xml, set the value of localrepository; (you need to copy setting from the Maven install directory/conf/directory to the. M2 directory)
(Dry--How to customize the local warehouse)
<!--localrepository | The path to the local repository maven would use to store artifacts. Default: ${user.home}/.m2/repository-- <localrepository>d:\classical_books\java_set\maven_in _action\local_repo\</localrepository>
3) Problem+solution:
3.1) Problem:
How does the widget get into the local repository? a component can only be used by other MAVEN projects afterit is in the local repository;
3.2) Solution: Execute mvn clean install command;
"3.2" Remote warehouse
1) Intro: when MAVEN is installed, the local repository directory will not exist without the MAVEN command, and MAVEN will create the local repository when the user enters the first MAVEN command, and then, depending on the configuration needs, Download artifacts from remote repositories to local repositories;
"3.3" central warehouse (belonging to the remote Warehouse, HTTPS://REPO.MAVEN.APACHE.ORG/MAVEN2)
1) Intro: Central Warehouse is the default remote warehouse (remote warehouse can be multiple), MAVEN installation comes with the configuration of the Central Warehouse;
(D:\classical_books\java_set\maven_in_ Action\apache-maven-3.3.9\lib\maven-model-builder-3.3.9\org\apache\maven\model\pom.xml file contents as follows)
<project> <modelVersion>4.0.0</modelVersion> <repositories> <repository > <id>central</id> <name>central repository</name> <url>https:// repo.maven.apache.org/maven2</url> <layout>default</layout> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories >
Analysis of the
above code: See the Enabled child element in the snapshots set to false, indicating that the snapshot version of the widget is not downloaded from the central repository;
"3.4"
1) Intro: Server is a special remote warehouse, it is set up in the local area network of the warehouse services, the Remote Storage Agent WAN on the network for the use of MAVEN users in the LAN;
2) Some artifacts that cannot be downloaded from an external repository can also be uploaded locally to be used by everyone, as shown in:
configuration of the "4" Remote repository
1) Default remote repository: <url>https://repo.maven.apache.org/maven2</url> as shown in the following code, this code is derived from the D:\classical _books\java_set\maven_in_action\apache-maven-3.3.9\lib\maven-model-builder-3.3.9\org\apache\maven\model\ Pom.xml (i.e. maven install directory/lib/..... )
<!--START Snippet:superpom--><project> <modelVersion>4.0.0</modelVersion> < repositories> <repository> <id>central</id> <name>central repository< /name> <url>https://repo.maven.apache.org/maven2</url> <layout>default</layout > <snapshots> <enabled>false</enabled> </snapshots> </ Repository> </repositories>
Analysis of the
above code: under the repositories element, one or more remote warehouses can be declared using the repository child element;
2) Release and snapshot, there are 3 sub-elements enabled + Updatepolicy + checksumpolicy;
2.1) The child element enabled:(True or False) indicates that download support for the snapshot version is turned on or off;
2.2) child elements Updatepolicy: (daily, never, Always, interval:x): Each is checked once a day, and other available values include: Never Never check for updates Always check for updates every time you build; interval:x Check for updates every X minutes ;
2.3) child element Checksumpolicy: a policy used to configure MAVEN inspection checks and files. When the component is deployed to the MAVEN repository, the corresponding checksum file is deployed simultaneously; (value can be set to ignore)
"4.1" Remote Warehouse certification
1) Configure the warehouse certification information in Settings.xml; (Configure authentication information for id==my-proj warehouses)
2) Configure the authentication information and configure the warehouse information is different: The warehouse information can be directly configured in the POM file, but the authentication information must be configured in the Settings.xml file, because the POM is often committed to all members of the Code warehouse access, And the settings.xml is put on the machine;
3) Assume that you need to configure authentication information for a id==my-proj warehouse, modify the settings.xml as follows:
4)maven uses the servers element and server child elements in the settings.xml file to configure the warehouse certification information;
Attention) The local warehouse of the machine is the remote warehouse of other machines;
"4.2" deployed to the remote repository
1) Maven can deploy the artifacts generated by the project to the warehouse. The deployment steps is as follows:
Step1) need to edit the project's Pom.xml file, configure the distributionmanagement element;
analysis of the
above code:
A0) configuration ID, name, URL as a unique identifier for the remote repository, Name and address;
A1) distributionmanagement contains The repository and snapshotrepository child elements, which represent warehouses for the release build artifacts, which represent the warehouse of the snapshot version;
A2) The key is the URL: It represents the address of the remote warehouse;
step2) when deploying artifacts to a remote repository, authentication is often required. in short, you need to create a server element in Settings.xml whose ID matches the ID of the remote repository and configure the correct authentication information
(see "6.4.1" certification content in the Remote Warehouse certification) STEP3) is configured correctly, run MVN clean deploy on the command line: maven deploys the artifacts of the project build output to the corresponding remote repository;
"5" snapshot version
1) Intro: the snapshot version (SNAPSHOT) is an unstable version, and the release version (release) is a stable version;
"6" mechanism for resolving dependencies from the warehouse
1) Intro: When the local repository is not dependent on artifacts, MAVEN will automatically download from the remote repository andmaven will automatically find the latest snapshot when the dependent version is the snapshot version. The underlying dependency resolution mechanism can be summarized as follows:
mechanism1) when the dependent range is system,maven directly from the local file system parsing the widget;
mechanism2) after calculating the warehouse path based on the dependent coordinates, try to find the component directly from the local warehouse, and if the corresponding component is found, the parsing is successful.
mechanism3) in the case where the local repository does not have a corresponding artifact, if the dependent version is an explicit release build widget, such as 1.2, then traverse all remote repositories, Discover, download and parse the use;
mechanism4) If the dependent version is release OR LATEST, the metadata for all remote warehouses is read based on the update policy Groupid/artifactid/ Maven-metadata.xml, after merging it with the corresponding metadata of the local repository, calculates the true value of RELEASE OR LATEST, and then checks the local repository and remote repository based on that value;
MECHANISM5) If the dependent version is SNAPSHOT, read the metadata groupid/artifactid/version/maven-metadata.xml for all remote warehouses based on the update policy, and After the corresponding metadata for the local warehouse is merged, the value of the latest snapshot version is obtained, and then the local warehouse is checked based on that value, or downloaded from the remote repository;
mechanism6) if the last resolved artifact version is a snapshot of the timestamp format, such as 1.4.1-200911-4.121450-121, copy the file in its timestamp format to a non-timestamp format, such as SNAPSHOT, and use the non- The component of the timestamp format;
....... 1000 words omitted here
"7" Mirror
1) Intro: if warehouse X can provide all the contents of the warehouse y storage, then it is possible for the X to be an image of Y, in other words, any artifact that can be obtained from the warehouse Y can be retrieved from his image;
(dry-image definition)
2) Edit the settings.xml, configure the central warehouse image
<mirrors> <!--mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | This mirror serves have an ID, that matches, the mirrorof element of this mirror. IDs is used | For inheritance and direct lookup purposes, and must is unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> < Name>human readable Name for this mirror.</name> <url>http://my.repository.com/repo/path</url > </mirror> </mirrors>
Analysis of the
above code:mirrorof Specifies the image of the central repository;
3) Another use of mirroring is the combination of the following: any required components can be obtained from the database, which is the mirror of all the warehouses;
4) to meet a number of complex requirements, MAVEN also supports more advanced mirroring configurations:
"8" Warehouse Search service
1) problem+solution:
1.1) Problem: How to find the dependencies you need, because adding Maven dependency needs to provide the exact MAVEN coordinates;
1.2) Use the MAVEN Warehouse search service sonatype Nexus (https://repository.sonatype.org/) http://mvnbrowser.com// http/ mvnrepository.com/(fastest access)
MAVEN (6) Warehouse