Common configuration of Maven's setting.xml and pom.xml

What is Maven:

The official definition of Maven is: Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.
Translation: Apache Maven is a software project management and understanding tool. Based on the concept of the Project Object Model (POM), Maven can manage project builds, reports and documentation from central information.
Maven is developed by java. For java, everything is an object, and our project is also an object. Maven defines and configures a project through the pom.xml file, and then builds and manages our project by parsing the pom file. Maven and springboot also follows the concept of convention over configuration, and has done a lot of default configuration and management for us.

Maven's setting.xml and pom.xml:


setting.xml is a global configuration of maven on the currently installed physical machine. As the main focus of java development, there are two places:

**localRepository**: It is to configure the machine that is currently being developed. jar Where the package is placed, which is what we usually call the local warehouse
**mirrors**: mirror list, when our local repository's jar The package does not support the build and runtime of our current project, at this time maven It will download what we need through the mirror configured in the mirror list jar Bag

Of course, if we are the architect or R&D director of the company, maybe we need to create a private maven repository of the current company. At this time, we need to pay attention to:

**servers**: Authentication configuration,maven Configure accounts, passwords, groups, permissions, where to access the file directory
**proxies**: Http proxy configuration,When private repositories don't have what we need jar package, it will access the external through the proxy maven repository to download jar Bag

Of course, if we need to have a deeper understanding of all setting configurations, we can check the official maven information of the corresponding version. The maven version I use is 3.6.0, and the address is:

The following are some configuration annotations of the default setting.xml file in maven

<?xml version="1.0" encoding="UTF-8"?>
<!-- maven of xml The specification that the configuration file follows, many frameworks or projects will xml When a file is used as a configuration file, it will have its own specification. Your configuration must follow this specification. When the framework or project parses the configuration file at work, it will also parse according to this specification. -->
<settings xmlns=""

<!-- Local repository, that is, what you installed maven the address on the disk of the physical machine, maven download jar will be stored here, the project is built jar The package is taken from here -->

  <!-- maven The global plug-in group, generally rarely configured here, is in the project xml document plugins medium configuration, such as our springboot packaged plugin for spring-boot-maven-plugin -->

  <!-- HTTP Where the proxy is set, generally a local maven As a team's private server, you need to configure this proxy, and you can't find it in the private server. jar The file will access the external network through this proxy to download what we need jar Bag -->

  <!-- Authentication configuration, when we put the maven As a private server or a privileged mirror, when you need to configure the privilege group and the user name and password under the group, it is configured here -->
 <!-- Mirror list, that is, we download jar place for package files -->
	<!-- specific mirror -->
		<!-- mirror Id,As the unique identifier of the image, it cannot be repeated -->
		<!-- Mirror name, just install your own preferences -->
		<name>aliyun maven</name>
		<!-- The address of the mirror, that is, we download jar package visit place -->
  <!-- The global configuration information group is generally not recommended to be configured globally here, it is all in the specific maven engineering pom file to configure -->
	 <!-- configuration information -->
		  <!-- The unique identifier of a specific configuration information -->
  <!-- The configuration information that is currently in effect is generally not configured in the global configuration. -->


As java development is more concerned but not very clear:
modelVersion The version of the POM file model is derived from the version of the super POM of maven installed on the current physical machine. The properties that we have not configured in the pom.xml under the project are all taken from the value in the super pom file. This super file is in the maven In maven-model-builder-3.6.0.jar in the lib folder of the installation directory

The places in the super pom file that are highly related to our usual work:

What else is there specifically, you can go to your maven directory to find this file to see
Scope: the scope of the current dependency, the default is: compile, other options: runtime, test, system, provided, what is the role, the official introduction is as follows:

Official address:

The address of the official configuration information of the pom file of maven3.6.0:
<?xml version="1.0" encoding="UTF-8"?>
<!-- maven Engineering POM file followed xml specification -->
<project xmlns="" xmlns:xsi=""
	<!-- POM The version of the file model, derived from the version installed on the current physical machine maven the super POM version of -->	 
	<!-- Child project declares parent project's information -->
        <relativePath/> <!-- lookup parent from repository -->
	<!-- Information about the current project -->
	<!-- Inversion of the domain name of the company or organization of the current project+The name of the project or plan, of course, can also be virtual, such as the name of a large company spring It's according to this rule -->
	<!-- module name -->
	<!-- version number -->
	<!-- project name -->
	<!-- project description -->
    <description>Demo project for Spring Boot</description>
	<!-- Version management of unified dependencies of the current project -->

	<!-- maven project dependent jar Bag,Will go to the local warehouse to find out if there is any specific jar package, there is no way to download what we need from the configured warehouse jar Bag -->
		<!-- specific dependencies -->
			<!-- of currently dependent components -->
			<!-- Inversion of the domain name of the company or organization of the current project+The name of the project or plan, of course, can also be virtual, such as the name of a large company spring It's according to this rule -->
			<!-- The name of the currently dependent module -->
			<!-- The version number of the currently dependent module -->
			<!-- The scope of the current dependency, the default is: compile,Other options: runtime, test, system, provided -->
			<!-- Configuration to exclude not imported jar,There are many under each dependent module jar package, which may also be introduced in other dependencies of the current project jar package, but the versions are different, maybe these two jar There will be conflicts, you can specify in one of the dependencies to be excluded jar -->

	<!-- maven Project build configuration -->
		<!-- Plugins used by the current project build -->
	<!-- Aggregation configuration, for example, microservices need to have various components and services. I want to give a folder outside to declare what this whole big project is for. At this time, aggregation will be used. -->
	<!-- Aggregation configuration, for example, one of my modules is more complicated. I need to split it into multiple projects, and this module also needs to be aggregated. At this time, this configuration will take effect. When aggregation is configured, other projects that are referenced will be automatically typed when packaging. become jar bag into lib Under contents -->
		<!-- Concrete modules owned by the aggregate -->
	<!-- Environmental management -->
	<!-- For the configuration of dependency management, for example, I have a parent project, and each subproject under the parent project has the same dependency import. At this time, I can do unified dependency version configuration management here, and introduce the same dependency of the unified version, of course, it will take effect. The dependencies are still the following
	Each sub-project's own POM The dependencies in the file, but if the version of the dependency is specified in this place, then if the subproject does not have a given version, the version number of this place will be used as the version number of the dependency introduced by the subproject. -->


Use of Maven:

maven creates projects. maven creates projects that are similar to the scaffolding of front-end vue projects. There are two types we commonly use:


Of course, there are two ways for maven to create a project. One is to execute the maven command in the directory where you want to create the project:

mvn -B archetype:generate -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4

The other is under development tools such as idea and eclipse

**maven The directory structure of the project:**
**pom**:pom It's us maven For a definition and configuration file for the entire project, maven It is through this file to build and manage our project
**src**:src Stored below are our code and some configuration files, as well as resource files, mian Below is the source code related, test The following is related to the test
**tartget**: Compile, run, test, package and generate related files will be stored in this directory

Commands commonly used by maven, if the maven command is not executed in the development tool, be sure to enter the directory where the pom file of the project you want to execute the command is located and execute these commands:

**mvn clean**: clean up target content
**mvn compile**: project compilation
**mvn test**:Execute current project test directory with Junit Annotated test cases will also generate results in target Under contents
**mvn package**: according to pom The packaging method of the file and the plug-in packaging, the generated package will be in the target Under contents
**mvn install**: Package the current project and publish the packaged files of the current project to the local repository
**mvn deploy** Package the current project and publish it to the remote warehouse. When the project team works together, the basic jar The update of the package must have this operation, otherwise the introduction of other projects will report an error, of course, you need to configure the address of the corresponding release warehouse

Tags: Java Operation & Maintenance Maven Spring Boot Back-end

Posted by ChibiGuy on Tue, 03 May 2022 20:15:50 +0300