在 Maven 中,<scope> 标签用于指定依赖的作用范围,控制依赖在项目的不同构建阶段(如编译、测试、运行、打包)中的可见性和行为。Maven 定义了以下几种主要的依赖范围(scope):
- compile
- provided
- runtime
- test
- system
- import
1. <scope>compile</scope>
- 默认范围:如果未指定
scope,默认为compile。 - 编译时可用:依赖在编译、测试和运行时都可用。
- 打包时包含:依赖会被打包到最终的可执行文件(如 JAR、WAR)中。
<dependency>
<groupId>org.example</groupId>
<artifactId>example-lib</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
2. <scope>provided</scope>
- 编译时可用:依赖在编译时可用。
- 运行时不可用:依赖在运行时不包含在最终的包中,需要由运行环境提供。
- 典型用途:用于依赖由容器或应用服务器提供的库,如 Servlet API。
<dependenc

5万+

被折叠的 条评论
为什么被折叠?



