<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Project Management on ottercoconut's Blog</title><link>https://ottercoconut.github.io/en/tags/project-management/</link><description>Recent content in Project Management on ottercoconut's Blog</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Tue, 01 Apr 2025 14:49:00 +0800</lastBuildDate><atom:link href="https://ottercoconut.github.io/en/tags/project-management/index.xml" rel="self" type="application/rss+xml"/><item><title>Maven Fundamentals</title><link>https://ottercoconut.github.io/en/p/maven-fundamentals/</link><pubDate>Tue, 01 Apr 2025 14:49:00 +0800</pubDate><guid>https://ottercoconut.github.io/en/p/maven-fundamentals/</guid><description>&lt;h3 id="reference-websites"&gt;Reference Websites
&lt;/h3&gt;&lt;p&gt;&lt;a class="link" href="https://liaoxuefeng.com/books/java/maven/index.html" target="_blank" rel="noopener"
 &gt;Maven Fundamentals - Java Tutorial - Liao Xuefeng&amp;rsquo;s Official Website&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="maven-fundamentals"&gt;Maven Fundamentals
&lt;/h2&gt;&lt;h3 id="introduction-to-maven"&gt;Introduction to Maven
&lt;/h3&gt;&lt;p&gt;Before understanding Maven, let&amp;rsquo;s look at what a Java project needs. First, we need to determine which dependency packages to introduce. For example, if we need to use &lt;a class="link" href="https://commons.apache.org/proper/commons-logging/" target="_blank" rel="noopener"
 &gt;commons logging&lt;/a&gt;, we must put the commons logging jar package into the classpath. If we also need &lt;a class="link" href="https://logging.apache.org/log4j/" target="_blank" rel="noopener"
 &gt;log4j&lt;/a&gt;, we need to put all log4j-related jar packages into the classpath. This is dependency management.&lt;/p&gt;
&lt;p&gt;Secondly, we must determine the directory structure of the project. For example, the &lt;code&gt;src&lt;/code&gt; directory stores Java source code, the &lt;code&gt;resources&lt;/code&gt; directory stores configuration files, and the &lt;code&gt;bin&lt;/code&gt; directory stores the compiled &lt;code&gt;.class&lt;/code&gt; files.&lt;/p&gt;
&lt;p&gt;Furthermore, we also need to configure the environment, such as the JDK version, the compilation and packaging process, and the version number of the current code.&lt;/p&gt;
&lt;p&gt;Finally, in addition to using IDEs like Eclipse for compilation, we must also be able to compile via command-line tools so that the project can be compiled, tested, and deployed on an independent server.&lt;/p&gt;
&lt;p&gt;These tasks are not difficult, but they are very tedious and time-consuming. If every project had its own set of configurations, it would certainly be a mess. What we need is a standardized Java project management and build tool.&lt;/p&gt;
&lt;p&gt;Maven is a management and build tool specifically created for Java projects. Its main features include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Providing a standardized project structure;&lt;/li&gt;
&lt;li&gt;Providing a standardized build process (compilation, testing, packaging, publishing&amp;hellip;);&lt;/li&gt;
&lt;li&gt;Providing a dependency management mechanism.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="maven-project-structure"&gt;Maven Project Structure
&lt;/h4&gt;&lt;p&gt;A typical Java project managed using Maven has the following default directory structure:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;a-maven-project
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;├── pom.xml
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;├── src
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ ├── main
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ │ ├── java
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ │ └── resources
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ └── test
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ ├── java
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ └── resources
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;└── target
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The root directory of the project &lt;code&gt;a-maven-project&lt;/code&gt; is the project name. It has a project description file &lt;code&gt;pom.xml&lt;/code&gt;. The directory storing Java source code is &lt;code&gt;src/main/java&lt;/code&gt;, the directory storing resource files is &lt;code&gt;src/main/resources&lt;/code&gt;, the directory storing test source code is &lt;code&gt;src/test/java&lt;/code&gt;, and the directory storing test resources is &lt;code&gt;src/test/resources&lt;/code&gt;. Finally, all files generated by compilation and packaging are placed in the &lt;code&gt;target&lt;/code&gt; directory. These constitute the standard directory structure of a Maven project.&lt;/p&gt;
&lt;p&gt;All directory structures are agreed-upon standard structures, and we must never modify the directory structure arbitrarily. Using the standard structure requires no configuration, and Maven can be utilized normally.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s look at the most critical project description file, &lt;code&gt;pom.xml&lt;/code&gt;. Its content looks like the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;project&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;modelVersion&amp;gt;&lt;/span&gt;4.0.0&lt;span class="nt"&gt;&amp;lt;/modelVersion&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;com.itranswarp.learnjava&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;hello&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;1.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;packaging&amp;gt;&lt;/span&gt;jar&lt;span class="nt"&gt;&amp;lt;/packaging&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;properties&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;project.build.sourceEncoding&amp;gt;&lt;/span&gt;UTF-8&lt;span class="nt"&gt;&amp;lt;/project.build.sourceEncoding&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;		&lt;span class="nt"&gt;&amp;lt;maven.compiler.release&amp;gt;&lt;/span&gt;17&lt;span class="nt"&gt;&amp;lt;/maven.compiler.release&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;/properties&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;dependencies&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.slf4j&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;slf4j-simple&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;2.0.16&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	&lt;span class="nt"&gt;&amp;lt;/dependencies&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/project&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Here, &lt;code&gt;groupId&lt;/code&gt; is similar to Java&amp;rsquo;s package name, typically the name of a company or organization. &lt;code&gt;artifactId&lt;/code&gt; is similar to a Java class name, typically the project name. Together with &lt;code&gt;version&lt;/code&gt;, a Maven project is uniquely identified by &lt;code&gt;groupId&lt;/code&gt;, &lt;code&gt;artifactId&lt;/code&gt;, and &lt;code&gt;version&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When we reference other third-party libraries, it is also determined through these 3 variables. For example, depending on &lt;code&gt;org.slfj4:slf4j-simple:2.0.16&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.slf4j&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;slf4j-simple&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;2.0.16&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;After declaring a dependency using &lt;code&gt;&amp;lt;dependency&amp;gt;&lt;/code&gt;, Maven will automatically download this dependency package and put it into the classpath.&lt;/p&gt;
&lt;p&gt;Additionally, note that &lt;code&gt;&amp;lt;properties&amp;gt;&lt;/code&gt; defines some properties. Commonly used properties are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;project.build.sourceEncoding&lt;/code&gt;: Indicates the character encoding of the project source code, typically set to &lt;code&gt;UTF-8&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maven.compiler.release&lt;/code&gt;: Indicates the JDK version to use, for example, &lt;code&gt;21&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maven.compiler.source&lt;/code&gt;: Indicates the source code version read by the Java compiler;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maven.compiler.target&lt;/code&gt;: Indicates the Class version compiled by the Java compiler.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Starting from Java 9, it is recommended to use the &lt;code&gt;maven.compiler.release&lt;/code&gt; property to ensure that the input source code and the compiled output version are consistent during compilation. If the source code and output versions are different, &lt;code&gt;maven.compiler.source&lt;/code&gt; and &lt;code&gt;maven.compiler.target&lt;/code&gt; should be set respectively.&lt;/p&gt;
&lt;p&gt;By defining properties via &lt;code&gt;&amp;lt;properties&amp;gt;&lt;/code&gt;, the JDK version can be fixed, preventing different developers of the same project from using different versions of the JDK.&lt;/p&gt;
&lt;h4 id="summary"&gt;Summary
&lt;/h4&gt;&lt;p&gt;Maven is a management and build tool for Java projects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Maven uses &lt;code&gt;pom.xml&lt;/code&gt; to define project content and utilizes a preset directory structure;&lt;/li&gt;
&lt;li&gt;Declaring a dependency in Maven can automatically download and import it into the classpath;&lt;/li&gt;
&lt;li&gt;Maven uses &lt;code&gt;groupId&lt;/code&gt;, &lt;code&gt;artifactId&lt;/code&gt;, and &lt;code&gt;version&lt;/code&gt; to uniquely locate a dependency.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id="dependency-management"&gt;Dependency Management
&lt;/h3&gt;&lt;p&gt;If our project depends on third-party jar packages, such as commons logging, the question arises: where do we download the published jar package for commons logging?&lt;/p&gt;
&lt;p&gt;If we also want to depend on log4j, what jar packages are needed to use log4j?&lt;/p&gt;
&lt;p&gt;Similar dependencies include: JUnit, JavaMail, MySQL driver, etc. A feasible method is to search for the project&amp;rsquo;s official website via a search engine, manually download the zip package, extract it, and put it into the classpath. However, this process is very tedious.&lt;/p&gt;
&lt;p&gt;Maven solves the dependency management problem. For example, our project depends on the jar package &lt;code&gt;abc&lt;/code&gt;, and &lt;code&gt;abc&lt;/code&gt; depends on the jar package &lt;code&gt;xyz&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;┌──────────────┐
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│Sample Project│
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;└──────────────┘
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; │
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ▼
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;┌──────────────┐
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ abc │
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;└──────────────┘
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; │
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ▼
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;┌──────────────┐
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ xyz │
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;└──────────────┘
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;When we declare the dependency for &lt;code&gt;abc&lt;/code&gt;, Maven automatically adds both &lt;code&gt;abc&lt;/code&gt; and &lt;code&gt;xyz&lt;/code&gt; to our project dependencies. We don&amp;rsquo;t need to manually investigate whether &lt;code&gt;abc&lt;/code&gt; requires &lt;code&gt;xyz&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Therefore, the first role of Maven is to resolve dependency management. We declare that our project needs &lt;code&gt;abc&lt;/code&gt;, Maven will automatically import the jar package of &lt;code&gt;abc&lt;/code&gt;, then determine that &lt;code&gt;abc&lt;/code&gt; needs &lt;code&gt;xyz&lt;/code&gt;, and will automatically import the jar package of &lt;code&gt;xyz&lt;/code&gt;. Thus, ultimately, our project will depend on both &lt;code&gt;abc&lt;/code&gt; and &lt;code&gt;xyz&lt;/code&gt; jar packages.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s look at a complex dependency example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-web&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;1.4.2.RELEASE&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;When we declare a &lt;code&gt;spring-boot-starter-web&lt;/code&gt; dependency, Maven will automatically parse and determine that approximately twenty or thirty other dependencies are ultimately required:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;span class="lnt"&gt;22
&lt;/span&gt;&lt;span class="lnt"&gt;23
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;spring-boot-starter-web
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; spring-boot-starter
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; spring-boot
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; sprint-boot-autoconfigure
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; spring-boot-starter-logging
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; logback-classic
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; logback-core
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; slf4j-api
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; jcl-over-slf4j
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; slf4j-api
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; jul-to-slf4j
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; slf4j-api
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; log4j-over-slf4j
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; slf4j-api
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; spring-core
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; snakeyaml
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; spring-boot-starter-tomcat
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; tomcat-embed-core
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; tomcat-embed-el
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; tomcat-embed-websocket
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; tomcat-embed-core
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; jackson-databind
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ...
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If we try to manually manage these dependencies ourselves, it is extremely time-consuming, laborious, and the probability of errors is very high.&lt;/p&gt;
&lt;h3 id="dependency-relationships"&gt;Dependency Relationships
&lt;/h3&gt;&lt;p&gt;Maven defines several dependency relationships, namely &lt;code&gt;compile&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;runtime&lt;/code&gt;, and &lt;code&gt;provided&lt;/code&gt;:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;scope&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;th&gt;Example&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;compile&lt;/td&gt;
 &lt;td&gt;This jar package is needed during compilation (default)&lt;/td&gt;
 &lt;td&gt;commons-logging&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;test&lt;/td&gt;
 &lt;td&gt;This jar package is needed when compiling tests&lt;/td&gt;
 &lt;td&gt;junit&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;runtime&lt;/td&gt;
 &lt;td&gt;Not needed during compilation, but required at runtime&lt;/td&gt;
 &lt;td&gt;mysql&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;provided&lt;/td&gt;
 &lt;td&gt;Needed during compilation, but provided by JDK or a server at runtime&lt;/td&gt;
 &lt;td&gt;servlet-api&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Among them, the default &lt;code&gt;compile&lt;/code&gt; is the most commonly used, and Maven will place dependencies of this type directly into the classpath.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;test&lt;/code&gt; dependencies indicate they are only used during testing and are not needed during normal execution. The most common &lt;code&gt;test&lt;/code&gt; dependency is JUnit:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.junit.jupiter&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;junit-jupiter-api&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;5.3.2&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;test&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;code&gt;runtime&lt;/code&gt; dependencies indicate they are not needed during compilation but are required at runtime. The most typical &lt;code&gt;runtime&lt;/code&gt; dependencies are JDBC drivers, such as the MySQL driver:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;mysql&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;mysql-connector-java&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;5.1.48&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;runtime&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;code&gt;provided&lt;/code&gt; dependencies indicate they are needed during compilation but not at runtime. The most typical &lt;code&gt;provided&lt;/code&gt; dependency is the Servlet API, which is needed during compilation; however, at runtime, the Servlet server has built-in related jars, so they are not needed during the execution phase:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;jakarta.servlet&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;jakarta.servlet-api&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;4.0.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;provided&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The last question is, how does Maven know where to download the required dependencies? That is, the related jar packages? The answer is that Maven maintains a central repository (&lt;a class="link" href="https://repo1.maven.org/" target="_blank" rel="noopener"
 &gt;repo1.maven.org&lt;/a&gt;), where all third-party libraries upload their own jars and related information. Maven can download the required dependencies from the central repository to the local machine.&lt;/p&gt;
&lt;p&gt;Maven does not download jar packages from the central repository every time. Once a jar package has been downloaded, it is automatically cached by Maven in a local directory (the &lt;code&gt;.m2&lt;/code&gt; directory in the user&amp;rsquo;s home directory). Therefore, apart from the first compilation being relatively slow due to the time needed for downloading, subsequent processes will not repeatedly download the same jar packages because of the local cache.&lt;/p&gt;
&lt;h4 id="unique-id"&gt;Unique ID
&lt;/h4&gt;&lt;p&gt;For any given dependency, Maven only needs 3 variables to uniquely identify a jar package:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;groupId: The name of the organization it belongs to, similar to a Java package name;&lt;/li&gt;
&lt;li&gt;artifactId: The name of the jar package itself, similar to a Java class name;&lt;/li&gt;
&lt;li&gt;version: The version of the jar package.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Through the above 3 variables, a certain jar package can be uniquely determined. Maven ensures that any jar package cannot be modified once published by performing PGP signing on the jar packages. The only way to modify a published jar package is to publish a new version.&lt;/p&gt;
&lt;p&gt;Therefore, once a jar package has been downloaded by Maven, it can be permanently and safely cached locally.&lt;/p&gt;
&lt;p&gt;Note: Only version numbers ending with &lt;code&gt;-SNAPSHOT&lt;/code&gt; are regarded by Maven as development versions. Development versions are repeatedly downloaded every time. Such SNAPSHOT versions can only be used in internal private Maven repos, and publicly published versions are not allowed to be SNAPSHOTs.&lt;/p&gt;

 &lt;blockquote&gt;
 &lt;p&gt;Henceforth, when we represent Maven dependencies, we use the abbreviated form groupId:artifactId:version, for example: org.slf4j:slf4j-api:2.0.4.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h4 id="maven-mirrors"&gt;Maven Mirrors
&lt;/h4&gt;&lt;p&gt;Besides downloading from Maven&amp;rsquo;s central repository, you can also download from Maven mirror repositories. If accessing Maven&amp;rsquo;s central repository is very slow, we can choose a faster Maven mirror repository. Maven mirror repositories synchronize periodically from the central repository:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;span class="lnt"&gt;7
&lt;/span&gt;&lt;span class="lnt"&gt;8
&lt;/span&gt;&lt;span class="lnt"&gt;9
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; slow ┌───────────────────┐
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ┌─────────────▶│Maven Central Repo.│
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; │ └───────────────────┘
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; │ │
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; │ │sync
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; │ ▼
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;┌───────┐ fast ┌───────────────────┐
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;│ User │─────────▶│Maven Mirror Repo. │
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;└───────┘ └───────────────────┘
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Users in the China region can use the Maven mirror repository provided by Alibaba Cloud. Using a Maven mirror repository requires configuration. In the user&amp;rsquo;s home directory, enter the &lt;code&gt;.m2&lt;/code&gt; directory and create a &lt;code&gt;settings.xml&lt;/code&gt; configuration file with the following content:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;settings&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;mirrors&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;mirror&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;id&amp;gt;&lt;/span&gt;aliyun&lt;span class="nt"&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;name&amp;gt;&lt;/span&gt;aliyun&lt;span class="nt"&gt;&amp;lt;/name&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;mirrorOf&amp;gt;&lt;/span&gt;central&lt;span class="nt"&gt;&amp;lt;/mirrorOf&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c"&gt;&amp;lt;!-- Alibaba Cloud&amp;#39;s Maven mirror is recommended in China --&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;url&amp;gt;&lt;/span&gt;https://maven.aliyun.com/repository/central&lt;span class="nt"&gt;&amp;lt;/url&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/mirror&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/mirrors&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/settings&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;After configuring the mirror repository, Maven&amp;rsquo;s downloading speed will be very fast.&lt;/p&gt;
&lt;h4 id="searching-for-third-party-components"&gt;Searching for Third-Party Components
&lt;/h4&gt;&lt;p&gt;The final question: if we want to reference a third-party component, such as &lt;code&gt;okhttp&lt;/code&gt;, how do we exactly acquire its &lt;code&gt;groupId&lt;/code&gt;, &lt;code&gt;artifactId&lt;/code&gt;, and &lt;code&gt;version&lt;/code&gt;? The method is to search for keywords via &lt;a class="link" href="https://search.maven.org/" target="_blank" rel="noopener"
 &gt;search.maven.org&lt;/a&gt;. After finding the corresponding component, directly copy it.&lt;/p&gt;
&lt;h4 id="command-line-compilation"&gt;Command Line Compilation
&lt;/h4&gt;&lt;p&gt;In the command line, navigate to the directory where &lt;code&gt;pom.xml&lt;/code&gt; is located, and enter the following command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-plain" data-lang="plain"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ mvn clean package
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If everything goes smoothly, you can obtain the automatically packaged jar after compilation in the &lt;code&gt;target&lt;/code&gt; directory.&lt;/p&gt;
&lt;h4 id="using-maven-in-an-ide"&gt;Using Maven in an IDE
&lt;/h4&gt;&lt;p&gt;Almost all IDEs have built-in support for Maven. In Eclipse, you can directly create or import a Maven project. If the imported Maven project has errors, you can try selecting the project, right-clicking, and choosing Maven - Update Project&amp;hellip; to update it.&lt;/p&gt;
&lt;h4 id="summary-1"&gt;Summary
&lt;/h4&gt;&lt;p&gt;Maven determines the jar packages required by the project through parsing dependency relationships. The 4 commonly used &lt;code&gt;scope&lt;/code&gt;s are: &lt;code&gt;compile&lt;/code&gt; (default), &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;runtime&lt;/code&gt;, and &lt;code&gt;provided&lt;/code&gt;;&lt;/p&gt;
&lt;p&gt;Maven downloads the required jar packages from the central repository and caches them locally;&lt;/p&gt;
&lt;p&gt;Downloading can be accelerated through mirror repositories.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id="build-process"&gt;Build Process
&lt;/h3&gt;&lt;p&gt;Maven not only has a standardized project structure, but it also has a standardized build process that can automatically automate compiling, packaging, publishing, and more.&lt;/p&gt;
&lt;h4 id="lifecycle-and-phase"&gt;Lifecycle and Phase
&lt;/h4&gt;&lt;p&gt;When using Maven, we first need to understand what Maven&amp;rsquo;s lifecycle is.&lt;/p&gt;
&lt;p&gt;Maven&amp;rsquo;s lifecycle consists of a series of phases. Taking the built-in lifecycle &lt;code&gt;default&lt;/code&gt; as an example, it includes the following phases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;validate&lt;/li&gt;
&lt;li&gt;initialize&lt;/li&gt;
&lt;li&gt;generate-sources&lt;/li&gt;
&lt;li&gt;process-sources&lt;/li&gt;
&lt;li&gt;generate-resources&lt;/li&gt;
&lt;li&gt;process-resources&lt;/li&gt;
&lt;li&gt;compile&lt;/li&gt;
&lt;li&gt;process-classes&lt;/li&gt;
&lt;li&gt;generate-test-sources&lt;/li&gt;
&lt;li&gt;process-test-sources&lt;/li&gt;
&lt;li&gt;generate-test-resources&lt;/li&gt;
&lt;li&gt;process-test-resources&lt;/li&gt;
&lt;li&gt;test-compile&lt;/li&gt;
&lt;li&gt;process-test-classes&lt;/li&gt;
&lt;li&gt;test&lt;/li&gt;
&lt;li&gt;prepare-package&lt;/li&gt;
&lt;li&gt;package&lt;/li&gt;
&lt;li&gt;pre-integration-test&lt;/li&gt;
&lt;li&gt;integration-test&lt;/li&gt;
&lt;li&gt;post-integration-test&lt;/li&gt;
&lt;li&gt;verify&lt;/li&gt;
&lt;li&gt;install&lt;/li&gt;
&lt;li&gt;deploy&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If we run &lt;code&gt;mvn package&lt;/code&gt;, Maven will execute the &lt;code&gt;default&lt;/code&gt; lifecycle, and it will run consistently from the beginning up until the &lt;code&gt;package&lt;/code&gt; phase:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;validate&lt;/li&gt;
&lt;li&gt;initialize&lt;/li&gt;
&lt;li&gt;&amp;hellip;&lt;/li&gt;
&lt;li&gt;prepare-package&lt;/li&gt;
&lt;li&gt;package&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If we run &lt;code&gt;mvn compile&lt;/code&gt;, Maven will also execute the &lt;code&gt;default&lt;/code&gt; lifecycle, but this time it will only run up to &lt;code&gt;compile&lt;/code&gt;, namely the following phases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;validate&lt;/li&gt;
&lt;li&gt;initialize&lt;/li&gt;
&lt;li&gt;&amp;hellip;&lt;/li&gt;
&lt;li&gt;process-resources&lt;/li&gt;
&lt;li&gt;compile&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another commonly used lifecycle in Maven is &lt;code&gt;clean&lt;/code&gt;, which executes 3 phases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;pre-clean&lt;/li&gt;
&lt;li&gt;clean (note that this clean is a phase, not a lifecycle)&lt;/li&gt;
&lt;li&gt;post-clean&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Therefore, when we use the &lt;code&gt;mvn&lt;/code&gt; command, the parameter following it is a phase, and Maven automatically runs up to the specified phase according to the lifecycle.&lt;/p&gt;
&lt;p&gt;A more complex example is specifying multiple phases. For example, running &lt;code&gt;mvn clean package&lt;/code&gt;, Maven first executes the &lt;code&gt;clean&lt;/code&gt; lifecycle and runs up to the &lt;code&gt;clean&lt;/code&gt; phase, then it executes the &lt;code&gt;default&lt;/code&gt; lifecycle and runs up to the &lt;code&gt;package&lt;/code&gt; phase. The actually executed phases are as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;pre-clean&lt;/li&gt;
&lt;li&gt;clean (note that this clean is a phase)&lt;/li&gt;
&lt;li&gt;validate (starts executing the first phase of the default lifecycle)&lt;/li&gt;
&lt;li&gt;initialize&lt;/li&gt;
&lt;li&gt;&amp;hellip;&lt;/li&gt;
&lt;li&gt;prepare-package&lt;/li&gt;
&lt;li&gt;package&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;During the actual development process, frequently used commands include:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;mvn clean&lt;/code&gt;: Cleans up all generated classes and jars;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;mvn clean compile&lt;/code&gt;: Cleans first, then executes up to &lt;code&gt;compile&lt;/code&gt;;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;mvn clean test&lt;/code&gt;: Cleans first, then executes up to &lt;code&gt;test&lt;/code&gt;. Because &lt;code&gt;compile&lt;/code&gt; must be executed before executing &lt;code&gt;test&lt;/code&gt;, there is no need to specify &lt;code&gt;compile&lt;/code&gt; here;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;mvn clean package&lt;/code&gt;: Cleans first, then executes up to &lt;code&gt;package&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;During the execution process of most phases, because we usually do not configure related settings in &lt;code&gt;pom.xml&lt;/code&gt;, these phases effectively do nothing.&lt;/p&gt;
&lt;p&gt;The phases that are frequently used are actually only a few:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;clean: clean up&lt;/li&gt;
&lt;li&gt;compile: compile&lt;/li&gt;
&lt;li&gt;test: run tests&lt;/li&gt;
&lt;li&gt;package: package&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="goal"&gt;Goal
&lt;/h4&gt;&lt;p&gt;Executing a phase subsequently triggers one or multiple goals:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Executed Phase&lt;/th&gt;
 &lt;th&gt;Corresponding Executed Goal&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;compile&lt;/td&gt;
 &lt;td&gt;compiler:compile&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;test&lt;/td&gt;
 &lt;td&gt;compiler:testCompile surefire:test&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The naming of a goal always takes the format of &lt;code&gt;abc:xyz&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Actually, if we draw an analogy, it becomes clear:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lifecycle is equivalent to a Java package; it contains one or multiple phases;&lt;/li&gt;
&lt;li&gt;phase is equivalent to a Java class; it contains one or multiple goals;&lt;/li&gt;
&lt;li&gt;goal is equivalent to a class method; it is actually the one doing the real work.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In most cases, we simply specify the phase, and it defaults to executing the goals bound by default to these phases. Only in a few instances do we directly specify running a goal, for example, starting a Tomcat server:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-plain" data-lang="plain"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ mvn tomcat:run
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h4 id="summary-2"&gt;Summary
&lt;/h4&gt;&lt;p&gt;Maven provides a standard build process through lifecycles, phases, and goals.&lt;/p&gt;
&lt;p&gt;The most commonly used build command entails specifying a phase, subsequently allowing Maven to execute up to the designated phase:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;mvn clean&lt;/li&gt;
&lt;li&gt;mvn clean compile&lt;/li&gt;
&lt;li&gt;mvn clean test&lt;/li&gt;
&lt;li&gt;mvn clean package&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Normally, we always execute the goals natively bound by default to the phase, so it is unnecessary to specify the goal.&lt;/p&gt;
&lt;hr&gt;</description></item></channel></rss>