On Fri, Jan 24, 2020 at 10:49 AM silkperformer <[email protected]> wrote: > Yes, but I have to implement a listener from this library.
You can split your plugin into three JARs (e.g., Maven modules in a reactor): · Some interfaces encapsulating how you wish to work with the library but without referring to any of its types, or your plugin’s types. · An implementation of those interfaces, depending on the first JAR as well as some minimal supported version of the library you expect to find (I am presuming it is versioned compatibly). · Your plugin, depending on the first JAR, and bundling the second JAR as a _resource_ (not a dependency). The plugin would then create a `URLClassLoader` containing the first and second JARs plus the actual library location on the agent, load the implementation class by name, cast it to the interface type, and work with it. The Maven complexity of all this is worth it if your interfaces are extensive. If you just need to call a couple methods from the library, it is easier to do that using reflection. If you need to implement a listener _interface_, you can do that via `Proxy`. If it is an abstract class, then things get trickier as you would need to use ASM or the to create a dynamic subclass. Also consider just interacting with the library via a command-line interface rather than trying to link against it at the Java level. -- You received this message because you are subscribed to the Google Groups "Jenkins Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr3M5%2BacS091a9Sbgi3RvNr0r1sOCn3ExW0jXzUwsQD9QA%40mail.gmail.com.
