假设有这样一个依赖关系,项目A依赖于项目B,项目B依赖于项目X和Y,B对于X和Y的依赖是可选依赖:A->B、B->X(可选)、B->Y(可选)。根据传递依赖的定义,如果所有这三个依赖范围都是compile,那木X、Y就是A的compile返元的传递性依赖,然而,由于这里XY是可选依赖,依赖不会得以传递。换句话说,XY将不会对A有任何影响。
optional:
Marks optional a dependency when this project itself is a dependency. Confused? For example,
imagine a project A that depends upon project B to compile a portion of code that may not
be used at runtime, then we may have no need for project B for all project. So if project Xadds project A as its own dependency, then Maven will not need to install project B at all.
Symbolically, if => represents a required dependency, and --> represents optional, although
A=>B may be the case when building A X=>A-->B would be the case when building X.
In the shortest terms, optional lets other projects know that, when you use this project, you do
not require this dependency in order to work correctly.
Maven-06可选依赖
最新推荐文章于 2024-06-06 15:01:28 发布