Maven 基础知识

官网: 传送门

Maven 项目结构

$ MavenProject
|-- pom.xml
|-- src
| |-- main
| | `-- java
| | `-- resources
| `-- test
| | `-- java
| | `-- resources
`-- README.md

POM文件

  • POM文件代表 工程对象模型(Project Object Model)它是使用Maven工作的基本组件,位于工程根目录。
  • POM文件支持继承
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>mscx-ad-discovery</module>
<module>mscx-ad-zuul</module>
<module>mscx-ad-gateway</module>
<module>mscx-ad-discovery-nacos</module>
<module>mscx-ad-common</module>
<module>mscx-ad-db</module>
<module>mscx-ad-sponsor</module>
<module>mscx-ad-search</module>
<module>mscx-ad-feign-sdk</module>
</modules> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <groupId>com.sxzhongf</groupId>
<artifactId>mscx-ad</artifactId>
<version>1.0-SNAPSHOT</version>
<name>分布式广告系统</name>
<description>基于Spring Cloud Alibaba 实现的分布式广告系统</description> <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <!--定义远程maven仓库-->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>alibaba</id>
<name>ali Milestones</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

Maven 坐标

Maven Dependency

Maven思想 是 约定大于配置,默认依赖中,scope 是compile.

Scope类型

  • compile(会被打包到当前project)

    表示被依赖的package参与当前project的编译,包含后续的测试,运行周期都会参与,是一个强依赖。

  • test

    表示被依赖的jar 仅参与测试相关的处理,包裹测试代码的编译,执行。(如junit)

  • runtime

    表示被依赖的jar不需要参与项目的编译,但是后期的测试和运行周期需要参与。

  • provided

    打包的时候不需要包含进去,其他的Container会提供该依赖支持,理论上该依赖可以参与编译、测试运行等周期 ,相当于compile,但是在打包阶段做了exclude命令。

  • system

    从参与环境来看,和provided相同,但是被依赖项不会从maven仓库获取,而是从本地文件系统获取,一定需要配合systemPath属性使用

  • import

    This scope is only supported on a dependency of type pom in the <dependencyManagement> section.

依赖传递特性

官方解释:传送门

  • Dependency mediation (最近依赖原则)

    "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies. For example, if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0.

    根据依赖深度,选择依赖路径最近的package version, 如果依赖深度相同,那么选择前一个。Note that if two dependency versions are at the same depth in the dependency tree, the first declaration wins.

  • Dependency management

    依赖管理(项目作者可直接指定依赖版本)

  • Dependency scope 如上一节所述

  • Excluded dependencies 排除依赖包中依赖项

  • Optional dependencies (相当于设置不允许将该依赖传递下去)

常用命令

最新文章

  1. NOIP2009潜伏者【B003】
  2. 使用mybatis-generator自动生成映射配置
  3. SQL获取本周销售总数
  4. hyper-v无线网络上外网
  5. 安装nginx python uwsgi环境 以及模拟测试
  6. ZOJ 1642 Match for Bonus (DP)
  7. 关于WPF中Popup控件的小记
  8. Swift开发之 ---- Swift宏定义
  9. careercup-数组和字符串1.5
  10. Java笔记--java一行一行写入或读取数据
  11. (转)Should I use char** argv or char* argv[]
  12. [Head First Python]1. 初始python-人人都爱列表
  13. GetBuffer与ReleaseBuffer的用法,CString剖析
  14. iphone之NSArray比较大小
  15. SSH是什么?Linux如何修改SSH端口号?
  16. 使用Windows2003创建DHCP服务器 - 进阶者系列 - 学习者系列文章
  17. 使用 IDEA 创建 Maven Web 项目 (异常)- Disconnected from the target VM, address: &#39;127.0.0.1:59770&#39;, transport: &#39;socket&#39;
  18. 走进javascript——解开switch之谜
  19. 201521123037 《Java程序设计》第7周学习总结
  20. 毕业设计——django中的render()与redirect()问题

热门文章

  1. go语言之变量
  2. 腾讯短信+SpringBoot+Redis实现注册逻辑
  3. linux-创建/使用快照/克隆(类似windows中备份还原)
  4. SSM框架之Mybatis(5)数据库连接池及事务
  5. Docker系列01-容器初探
  6. Linux:nginx服务器的搭建
  7. Mysql—下载安装与使用
  8. [转]java 通过反射获取类的全局变量、方法、构造方法
  9. idea安装以及使用
  10. Java编译器的2点优化