How do optional dependencies work?
Project-A -> Project-B
The diagram above says that Project-A depends on Project-B. When A declares B as an optional dependency in its POM, this relationship remains unchanged. Its just like a normal build where Project-B will be added in its classpath.
Project-X -> Project-A
But when another project(Project-X) declares Project-A as a dependency in its POM, the optional dependency takes effect. You'll notice that Project-B is not included in the classpath of Project-X; you will need to declare it directly in your POM in order for B to be included in X's classpath.
更多详细:http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
从官网可以看出
如果项目a依赖redis,而且方式为optional
那么,如果项目b依赖项目a,项目b中的classpath是没有redis的依赖的,只有显示的添加redis的依赖才有(去掉optional)
网友评论