官方文档的说法是,当 project-A 依赖 project-B,project-B 依赖 project-D 时。
What if we dont want project D and its dependencies to be added to Project A's classpath because we know some of Project-D's dependencies (maybe Project-E for example) was missing from the repository, and you don't need/want the functionality in Project-B that depends on Project-D anyway. In this case, Project-B's developers could provide a dependency on Project-D that is <optional>true</optional>, like this:
<dependency>
<groupId>sample.ProjectD</groupId>
<artifactId>ProjectD</artifactId>
<version>1.0-SNAPSHOT</version>
<optional>true</optional>
</dependency>
所以当project-B的<optional>true</optional>时,project-A中如果没有显式的引入project-D,则project-A不依赖project-D,即project-A可以自己选择是否依赖project-D。
默认<optional>的值为false,及子项目必须依赖。