adobe / aio-lib-java-cloudmanager

Java wrapper to the Adobe Cloud Manager API.
https://opensource.adobe.com/aio-lib-java-cloudmanager/
Apache License 2.0
3 stars 9 forks source link

java.lang.NoSuchMethodError: 'void javax.ws.rs.core.MultivaluedMap.addAll(java.lang.Object, java.lang.Object[])' when used in Jenkins #20

Closed kwin closed 3 years ago

kwin commented 3 years ago

I use the client in a Jenkins Shared Library via

@Grab(group='io.adobe.cloudmanager', module='aio-lib-cloudmanager', version='0.4.0')

When trying to get the token I run into the following exception

java.lang.NoSuchMethodError: 'void javax.ws.rs.core.MultivaluedMap.addAll(java.lang.Object, java.lang.Object[])'
    at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:322)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.accept(JerseyInvocation.java:224)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.accept(JerseyInvocation.java:147)
    at io.adobe.cloudmanager.jwt.swagger.invoker.ApiClient.invokeAPI(ApiClient.java:696)
    at io.adobe.cloudmanager.jwt.swagger.api.JwtApi.authenticate(JwtApi.java:109)
    at io.adobe.cloudmanager.impl.IdentityManagementApiImpl.authenticate(IdentityManagementApiImpl.java:73)
    at io.adobe.cloudmanager.impl.IdentityManagementApiImpl.authenticate(IdentityManagementApiImpl.java:67)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
    at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at customGroovyscript.....

The reason for that is that the Java library requires JAX-RS 2.0.0 while Jenkins still seems to ship with JAX-RS 1.1.0 (or older): https://stackoverflow.com/a/44070033.

kwin commented 3 years ago

Was there a particular reason why jersey2 was used as library (https://github.com/adobe/aio-lib-java-cloudmanager/blob/8ad4eab0363fdc02a95681a729878d48bc53ab8e/pom.xml#L131). To me it seems that the default http client + json parser okhttp-gson could be less conflicting, as it doesn't require JAX RS 2.0.

kwin commented 3 years ago

The classpath in Jenkins seems to be a mess. A similar issue was reported in https://issues.jenkins.io/browse/JENKINS-44378. I am still unsure which plugin include JAX-RS 1.x or whether this is provided by the Jenkins Core.

bstopp commented 3 years ago

Jersey2 was used as I was most familiar with it.

This issue seems to be specific to using the library in the context of Jenkins. While it is a/the primary use case for this, it is an issue related to that context, and not necessarily something that this project needs to resolve.

As a side note, from the Jenkins documentation:

While possible, accessing third-party libraries using @Grab from trusted libraries has various issues and is not recommended.

Link

Seems as if Jenkins context is unlikely to work using the @Grab notation regardless.

kwin commented 3 years ago

When you recommend using an external binary one could use the aio-cli in the first place. I would still say that executing this library inside a Jenkins Shared Library should be supported (deploying an external tool requires some effort). Let me try to come up with a fix which relies on shading and relocation

kwin commented 3 years ago

Just for the reference: The Groovy Shared Library uses a class loader which merges all plugin classloaders. This is a parent class loader of the Grapes class loader and therefore used preferably. In my case it was the JIRA Trigger Plugin which included Jersey Core 1.5 (which includes javax.ws.rs.core..MultivaluedMap from JAX-RS 1.x). After that plugin was removed, it works.