Suggested Pages

Tuesday, February 7, 2017

Maven Optional Dependency

Here an example of maven optional usage:

Maven Optional can be described as a dependency that is marked as excluded by default. This means that if your project X depends on a specific library Y that declares a dependency with Z as optional, then your project X does not include Z as library because it is considered optional.

Because of this all the functionalities of Y that does not regard Z can be used normally, but the functionality expressed by Z cannot be used by project X unless X declares a specific dependency on Z.

project Y
       
 
     <dependency>
      <groupId>groupZ</groupId>
      <artifactId>Z</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
     <optional>true</optional>
     </dependency>
As you can see project X should include and direct dependency on Z if the project X needs the functionality of the project Y expressed by project Z. project X
       
  <dependencies> 

     <dependency>
      <groupId>groupY</groupId>
      <artifactId>Y</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
    </dependency>
 
     <dependency>
      <groupId>groupZ</groupId>
      <artifactId>Z</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
       </dependency>

  </dependencies> 

No comments :

Post a Comment

Suggested Pages