Maven scope和optional

455 阅读1分钟

1.scope

maven中的scope可以定义该依赖的生命周期,默认的是compile。
scope定义为provider,该依赖将不会被传递,只有编译时会被使用

2.optional

optional可以决定该依赖是否被依赖。
maven.apache.org/guides/intr…

3.scope provider vs optional true

scope选择provider和optional为true,在功能上确实能实现相同,但是他们做的事情并不相同。
语意层就是不同的:
scope 为provider,可能容器就有这个jar包,web应用在打包时不必再将其打包。
optional为true,使用该依赖的项目可能并不需要使用optional为true所依赖的jar的相应功能。
Project B has many features but during the development of some features we have used some capabilities of Project C. However, those features are optional, that means you don’t have to use them in your project. Therefore, you don’t need Project C in your classpath unless you want to use those features of Project B that depends on Project C medium.com/@danismaz.f…