'How can I pass only Exceptions from my Java Library to the implementing application?

According to the Gradle Documentation you can include a dependency as "API" meaning it will be passed on to the application implementing it's class path. Is there a way to pass only an individual class/exception instead of the entire dependency?

Example

In Library A (written by me) I am using Open SAML Core. The Class CoolClass in the library throws Exception B (from Open SAML Core). The build.gradle file includes:

dependencies {
    implementation group: 'org.opensaml', name: 'opensaml-core', version: "24.0.2"

In Java Application C, I am implementing Library A. If I use CoolClass in my application, then gradle build gives me the following error:

/ApplicationC/src/main/java/com/sorry/CoolClass.java:10: error: cannot access ExceptionB
                                           .someMethod();
                                                       ^
  class file for org.opensaml.core.xml.io.ExceptionB not found

Is there a way to pass just that exception rather than including the entire library in the class path of my application?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source