Maven依赖管理

Maven依赖管理

  1. 在pom.xml中编写<dependencies>标签
  2. <dependencies>标签中使用<dependency>引入坐标
  3. 定义坐标的groupId, artifactId, version
  4. 点击刷新按钮,做坐标生效

alt+insert导入本地库中的jar包

设置自动刷新

依赖范围

通过设置坐标的依赖范围(scope),可以设置对应jar包的作用范围:编译环境、测试环境、运行环境

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.2</version>
    <scope>test</scope>
</dependency>

<scope>默认值:compile

依赖传递

可选依赖与排除依赖