scope属性
compile
,默认值,表示此依赖包出现在任何classpath内,依赖传递test
,表示此依赖包只出现在与测试相关的classpath内,默认情况下,只有src/main/test/java
路径下的类可以引入此依赖包中的类,依赖不传递provided
,表示此依赖出现在非运行时环境的classpath内,依赖不传递runtime
,表示此依赖出现在与测试相关和运行时的classpath,依赖传递system
,表示此依赖出现在非运行时环境的classpath内,依赖不传递
optional属性
false
,默认值,表示传递性由scope
属性来指定true
,表示依赖不传递
对打包的影响
- Maven打JAR包默认不会把依赖包打进包内,如果需要把依赖包也打进包内,需要使用
maven-assembly-plugin
插件 - Maven打WAR包,根据依赖的传递性来决定是否将依赖包打进WAR包,依赖传递的默认打进去
- Spring Boot使用
spring-boot-maven-plugin
打大JAR包,在Maven打WAR包规则的基础上,默认会将scope
为provided
和optional
为true
的包打进去,需要通过配置来排除
Spring Boot打包排除依赖包例子
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
PREVIOUS基于MyBatis-Plus实现自定义通用数据库服务
NEXTSpring定时任务使用