How to import / export runtime dependency with OSGi in app using a native library to avoid classloader problem

We have a use case where we have to send each content that gets published in Enonic XP admin to an external system for search purposes. To solve this we have written a java class implementing com.enonic.xp.event.EventListener that pushes each published content to a Queue in Windows server 2012.

We use an external library MsmqJava that uses System.loadLibrary(“MsmqJava”) in a static initializer block to load a system dll. We have included this library in the app in build.gradle with
include 'ionic.Msmq:MsmqJava:

The problem here is that the Enonic XP server has to be restarted for each re-deploy of the app, because if not we get a “java.lang.UnsatisfiedLinkError: Native library MsmqJava.dll already loaded in another classloader” because of the static loading of the native library in the external dependency.

The external library never changes, so a good solution would be to drop the external library MsmqJava.jar inside the Enonic XP lib folder or jdk\jre\lib\ext folder and load the library as a runtime dependency, I would typically use “provided” scope in maven pom.xml. What is the solution here to declare a runtime dependency in build.gradle file? I assume because the jar-files deployed in Enonic XP are OSGi bundles, they require import/export declarations in its MANIFEST.MF file. Are there any examples on how to configure this?