Maven
- Maven仓库
- 快速查找jar包,形成依赖xml语言
- 项目管理工具,依赖管理,构建生命周期/阶段
POM project Object Model,项目对象模型
- 仓库,存储资源和各种jar包
- 坐标,Maven中的仓库位置
groupId定义当前Maven项目隶属的组织名称
artifactId定义当前Maven项目名称
version定义当前项目版本号
pom.xml文件依赖示例
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.9.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
war类型为webapp,jar类型为默认java
- 项目构建生命周期
compile->test-compile->test->package->install
依赖
- 路径优先,层级越深,优先级越低
- 声明优先,相同层级,配置顺序靠前的覆盖顺序靠后的
- 特殊优先,相同资源的不同版本,后配置的覆盖先配置的
- 可选依赖,隐藏依赖
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>juint</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
| scope | 主代码 | 测试代码 | 打包 |
|---|
| compile(默认) | Y | Y | Y |
| test | | Y | |
| provided | Y | Y | |
| runtime | | | Y |
Maven生命周期
- clean 清理工作
- default 核心工作,例如编译,测试,打包,部署
- site 产生报告,发布站点
- 插件,与生命周期内的阶段绑定,在执行到对应生命周期时,执行对应的插件功能
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
//目标打包文件
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
//运行时期
<phase>generate-test-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
构建管理
- 打包形式为pom
<packaging>pom</packaging>
- 用专门的模块,管理其他模块的更新
- 调用顺序根据依赖关系执行
<modules>
<module>模块路径<modeule>
</modules>
依赖继承
- 声明依赖管理,所有依赖全部放在这里面,管理其他模块的依赖版本
<dependencyManagement></dependencyManagement>
<pluginManagement></pluginManagement>
<parent>
<>文件定位<>
<relativePath>父工程的pom文件</relativePath>
</parent>
属性
<properties>
<propertiy>
<spring.version></spring.version>
</propertiy>
</properties>
//使用
${junit.version}
<resources>
<resource>
<directory>资源文件夹路径</directory>
<filtering>true</filtering>
</resource>
</resources>
多环境配置
<profiles>
<profile>
//环境名
<id>pro_env</id>
//环境配置
<properties>
<junit.version>4.12</junit.version>
</properties>
//默认启动
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
install -P 环境名
跳过测试
install -D skipTests
- maven窗口的
Toogle闪电按钮
- pom文件
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/测试类名</include>
</includes>
<excludes>
<exclude></exclude>
</excludes>
</configuration>
</plugin>
Nexus私服
- 下载链接
- idea通过本地仓库与私服建立连接
- 发布到私服上
<distributionManagement>
<repository>
<id>仓库</id>
<url>地址</url>
</repository>
</distributionManagement>