Maven3.x兼容笔记

一、依赖解析

The core of Maven 3 uses Aether for dependency resolution. Aether employs a different approach to calculate the transitive dependencies and is meant to fix some of the trickier (conflict) resolution issues within Maven 2.x.

In practice, this change can result in different class paths especially for projects with big/complex dependency graphs. For instance, projects that erroneously have conflicting dependencies on their classpath might encounter build issues depending on the classpath order. See JETTY-1257 for a concrete example of this issue.

阅读更多

Maven如何处理循环依赖

一、Reactor对Project中model循环依赖检测

  • 发生阶段:开始构建时,解析project的model解析顺序

  • 检测到循环依赖时动作:抛出异常,终止解析

阅读更多

Maven源码-依赖解析

一、依赖解析流程说明

1)通过DefaultModelBuilder#build生成当前pom的Model,也就是effective pom

2)递归解析(深度遍历)effective pom的child dependency,生成effective pom

阅读更多

Maven源码-主流程

一、MavenCli#main

maven使用Plexus容器(一种IOC容器)进行MOJO等管理,apache-maven/src/bin/m2.conf里声明了其主类org.apache.maven.cli.MavenCli:

1
2
3
4
5
6
7
8
main is org.apache.maven.cli.MavenCli from plexus.core

set maven.conf default ${maven.home}/conf

[plexus.core]
load ${maven.conf}/logging
optionally ${maven.home}/lib/ext/*.jar
load ${maven.home}/lib/*.jar
阅读更多

Maven依赖协调原则及依赖顺序的影响

一、Maven依赖协调原则

1)POM的直接依赖,后声明的依赖有效

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>person.kivihub</groupId>
<artifactId>maven-demo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<dependencies>
<!-- 被覆盖 -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.17</version>
</dependency>
<!-- 有效 -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.2</version>
</dependency>
</dependencies>
</project>
阅读更多

打包后-JAR包名为时间戳orSNAPSHOT

一、现象

通过maven-assembly-plugin插件打包,发现lib里有的Jar包格式为artifact-demo-1.0.SNAPSHOT.jar,而有的格式为artifact-demo-1.0.20211123.202203-4.jar

有个明显的现象是执行mvn clean package命令时,所编译的module后缀皆为SNAPSHOT。

阅读更多

Maven生命周期和插件MOJO

一、插件命名

You will typically name your plugin <yourplugin>-maven-plugin.

Calling it maven-<yourplugin>-plugin (note “Maven” is at the beginning of the plugin name) is strongly discouraged since it’s a reserved naming pattern for official Apache Maven plugins maintained by the Apache Maven team with groupId org.apache.maven.plugins. Using this naming pattern is an infringement of the Apache Maven Trademark.

阅读更多

Maven常用命令

常用命令

1)只处理当前Pom,不递归处理子module

-N –non-recursive Do not recurse into sub-projects

阅读更多

DependencyManagment作用

介绍

Dependency management:this allows project authors to directly specify the versions of artifacts to be used when they are encountered in transitive dependencies or in dependencies where no version has been specified.

阅读更多

Maven仓库更新策略

maven仓库的更新策略指的是更新maven-metadata-[repository].xml,即何时触发从远程仓库读取最西的’maven-metadata-[repository].xml’的策略。

一、Maven下载仓库配置

阅读更多

maven插件的依赖的查找顺序

maven的依赖下载和查找逻辑

  1. 优先下载标签里的依赖及其间接依赖;
    1)从lib-snapshot,lib-release中仓库下载到本地仓库,并copy到项目target目录;
阅读更多