maven基本概念

Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建、报告和文档的软件项目管理工具。

安装

http://maven.apache.org/download.cgi
image.png

groupId的值就是项目的包名
artifactId是模块/项目名

mvn常用命令

mvn compile 对项目进行编译
mvn test 测试
mvn package 打jar包
mvn clean删除target
mvn install安装jar包到本地仓库

archetype插件用于创建符合maven规定的目录骨架
mvn archetype:generate 按照提示进行选择
mvn archetype:genetate -DgroupId=...

maven中的坐标和仓库

groupId + artifactId + version 组成坐标
仓库:

  • 本地仓库
  • 远程仓库
    镜像仓库
    配置地址:apache-maven-3.6.0/conf/settings.xml
  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  </mirrors>

##更改本地仓库位置

 <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->

maven的生命周期和插件

  • clean 清理项目
    • pre-clean 执行清理前的工作
    • clean 清理上一次构建生成的所有文件
    • post-clean 执行清理后的文件
  • default 构建项目(最核心)
    • compile
    • test
    • package
    • install
  • site 生成项目站点
    • pre-site 在生成项目站点前要完成的工作
    • site 生成项目的站点文档
    • post-site 在生成项目站点后要完成的工作
    • site-deploy 发布生成的站点到服务器上

clean、compile、test、package(complile test)、install

完整的项目构建过程包括:
清理、编译、测试、打包、集成测试、验证、部署

pom的常用元素

project根元素,包含一些约束信息
modelVersion固定的版本 例如4.0.0
groupId + artifactId + version + packaging(不指定时默认为jar) 项目坐标
name项目描述名
describtion项目描述
url项目地址

optional 设置依赖是否可选

  • false 子项目默认为继承
  • true 子项目必须显示引用该依赖
    exclusions排除依赖传递列表

dependencyManagement主要定义在父模块中,子模块可以直接继承

插件列表

		<plugins>
			<plugin>
				<groupId>...</groupId>
				<artifactId>...</artifactId>
			</plugin>
		</plugins>
	</build>

依赖冲突

  • 短路优先
  • 先声明先优先
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值