I've got a multi-project application where we use a library, oshi, that depends on version 4.2.2 of JNA. In our project itself, we use 4.3.0, which hasn't been released yet. We made a contribution that will be in 4.3.0 when it ever gets released, but we need it right now, so we currently use a forked version that we build ourselves.
We package everything up using the maven shade plugin. Currently, the shade plugin uses 4.3.0 in the uberjar.
The problem is that oshi uses a function in 4.2.2 that doesn't seem to be in 4.3.0. The interface we are using was changed, and now we get NoSuchMethodError exception. The exception we get looks like this:
org.quartz.JobExecutionException: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NoSuchMethodError: com.sun.jna.platform.win32.OleAuto.VariantClear(Lcom/sun/jna/Pointer;)Lcom/sun/jna/platform/win32/WinNT$HRESULT;]
at org.quartz.core.JobRunShell.run(JobRunShell.java:218) [quartz-2.2.3.jar:?]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.3.jar:?]
Caused by: org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-2.2.3.jar:?]
... 1 more
Caused by: java.lang.NoSuchMethodError: com.sun.jna.platform.win32.OleAuto.VariantClear(Lcom/sun/jna/Pointer;)Lcom/sun/jna/platform/win32/WinNT$HRESULT;
at oshi.util.platform.windows.WmiUtil.enumerateProperties(WmiUtil.java:504) ~[oshi-core-3.2.jar:3.2]
at oshi.util.platform.windows.WmiUtil.queryWMI(WmiUtil.java:304) ~[oshi-core-3.2.jar:3.2]
at oshi.util.platform.windows.WmiUtil.selectUint32sFrom(WmiUtil.java:112) ~[oshi-core-3.2.jar:3.2]
at oshi.hardware.platform.windows.WindowsGlobalMemory.updateSwap(WindowsGlobalMemory.java:74) ~[oshi-core-3.2.jar:3.2]
at oshi.hardware.common.AbstractGlobalMemory.getSwapTotal(AbstractGlobalMemory.java:82) ~[oshi-core-3.2.jar:3.2]
So what I need to do is figure out how to have both versions in the uberjar.
I've tried relocating the 4.3.0 version, but it didn't seem to work (the classes weren't in the uberjar anywhere). Further I swear I read earlier today (but of course can't find it now) that the pattern in the relocation field is groupId:artifactId[:type][:classifier]
with no option for version.
The relevant portion of my dependency tree looks like this:
myproject
+-oshi-core
| +- jna 4.2.2
+-jna 4.3.0-CUSTOM
Can anyone give me any suggestions on how to resolve this? Thanks!