十三、Maven: 新建Maven项目之pom.xml文件

<?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>

    <groupId>com.yust5273</groupId>
    <artifactId>maven-first-project</artifactId>
    <version>1.0-SNAPSHOT</version>

</project>

modelVersion: 指的就是


15956200-795817b7c79e360e.png

groupId com.公司网站名.部门/项目
artifactId 功能命名
version 版本号
packaging 打包方式 默认是jar

父pom中的properties:


    <properties>
        <!-- Test -->
        <junit.contrib.version>1.16.1</junit.contrib.version>
    </properties>
使用

        <dependency>
            <groupId>com.github.stefanbirkner</groupId>
            <artifactId>system-rules</artifactId>
            <version>${junit.contrib.version}</version>
            <scope>test</scope>
        </dependency>
可以使用${标签名}来使用在<properties>标签里所定义的<标签>值</标签>
有什么用呢,可以作为全局变量来用,改变该全局变量的值,所有引用该全局变量的值也随着改变,方便维护

dependencyManagement:

  1. 只能出现在父pom
  2. 统一版本号
  3. 声明 (子POM里用到再引) 只是一个声明,如果需要使用,还需要在子pom中引入该依赖,不用写version

Dependency

  1. Type 默认jar
  2. scope
    a) compile 编译 例如spring-core
    b) test 测试
    c) provided编译 例如 servlet
    d) runtime运行时 例如JDBC驱动实现
    e) system 本地一些jar 例如短信jar
    f) 依赖传递
    第一列表示直接依赖的scope,第一行表示间接依赖的scope
    compile test provided runtime
    compile compile - - runtime
    test test - - test
    provided provided - provided provided
    runtime runtime - - runtime

============================
使用mvn dependency:tree 命令可查看依赖树

转载于:https://www.jianshu.com/p/ec2ff5046bff

猜你喜欢

转载自blog.csdn.net/weixin_34122810/article/details/91318831
今日推荐