maven必须要掌握的基础知识

1 篇文章 0 订阅

1.常用命令

mvn -v 查看版本信息
compile 编译
test 测试
package 打包

clean 删除target目录
install 安装jar包到本地仓库

2.maven 的仓库

Maven中的仓库分为两种:Snapshot快照仓库和Release发布仓库。
Snapshot快照仓库用于保存开发过程中的不稳定版本.
Release正式仓库则是用来保存稳定的发行版本。

<version>0.1-SNAPSHOT</version>

3.创建目录的两种方式

1.archetype:generate 按照提示进行选择

2.archetype:generate -DgroupId=组织名, 公司名字的反写+项目名
-DartifactId=项目名-模块名
-Dversion=版本号
-Dpackage=代码所在的包名

4.更改maven默认jdk版本号

1.右键properties更改
只更改当前模块,下次新建还要更改
在这里插入图片描述

2.更改settings.xml文件,补充这段代码

 <profile>      
   <id>jdk-1.8</id>  
   <activation>             
    <activeByDefault>true</activeByDefault>
    <jdk>1.8</jdk>         
   </activation>   
   <properties>   
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>   
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>   
   </properties>
  </profile>

5.聚合,依赖

聚合,方便项目多个模块install等操作

   <packaging>pom</packaging>
   <modules>
      <module>../shuyuan-fuzi(模块名)</module>
      <module>../shuyuan-limanman(模块名)</module>
      <module>../shuyuan-ningque(模块名)</module>

     </modules>

依赖

以junit为例

  <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <junit.version>3.8.1</junit.version>
    </properties>
  
   <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
      </dependency>
    </dependencies>
   </dependencyManagement>

其他模块:

 <parent>
    版本号+坐标
   </parent>

6.maven依赖冲突(短路优先)

例子:模块B依赖模块A模块C依赖模块B

A,B都有插件junit 但版本不一样,C优先B的junit的版本号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值