2

We are developing a Jenkins plugin that communicate with Stash and also depends on the Jenkins git plugin.

When navigating to one of the page exposed by our plugin, I have the following stacktrace:

java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.http.conn.ssl.SSLContextBuilder.loadTrustMaterial(Ljava/security/KeyStore;Lorg/apache/http/conn/ssl/TrustStrategy;)Lorg/apache/http/conn/ssl/SSLContextBuilder;" the class loader (instance of hudson/ClassicPluginStrategy$AntClassLoader2) of the current class, org/jenkinsci/plugins/hjs/git/stash/StashHttpClient, and the class loader (instance of hudson/ClassicPluginStrategy$AntClassLoader2) for the method's defining class, org/apache/http/conn/ssl/SSLContextBuilder, have different Class objects for the type org/apache/http/conn/ssl/TrustStrategy used in the signature
at org.jenkinsci.plugins.hjs.git.stash.StashHttpClient.getSslConnectionSocketFactory(StashHttpClient.java:104)
at org.jenkinsci.plugins.hjs.git.stash.StashHttpClient.getBranches(StashHttpClient.java:78)
at org.jenkinsci.plugins.hjs.git.stash.StashHttpClient.getBranches(StashHttpClient.java:73)
at org.jenkinsci.plugins.hjs.sync.SyncAnalyser.analyseRemoteBranches(SyncAnalyser.java:71)
at org.jenkinsci.plugins.hjs.sync.SyncAnalyser.analyze(SyncAnalyser.java:48)
at org.jenkinsci.plugins.hjs.sync.SyncReportAction.getReport(SyncReportAction.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.commons.jexl.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:258)
at org.apache.commons.jexl.parser.ASTMethod.execute(ASTMethod.java:104)
[...]

My understanding is that the Jenkins Git plugin has a dependency on Apache httpclient, and my plugin also has a dependency on httpclient. Somehow those 2 clash at some point.

I tried to mark my dependencies to httpclient as <scope>provided</scope> and with the same version as the one provided by the Jenkins Git plugin. Still the same error.

I checked that my .hpj file does not contain the httpclient jars.

What else should I investigate ? Any good documentation on how classloader work in Jenkins ?

Guillaume
  • 18,494
  • 8
  • 53
  • 74
  • Ran into virtually the same issue (for ages) - mine was a conflict between the version of apache http-client I needed to use and the super old version referenced in the maven-plugin. You might find in your case there are more plugins which reference http-client so your're clashing with something other than git-plugin. – Tom Feb 08 '16 at 10:26
  • I battled with directly trying to tell the classloader (in-code) which version of the library to choose - with no luck. I ended up switching to [Google's http-client](https://developers.google.com/api-client-library/java/google-http-java-client/) which does all the same stuff (and in fact uses apache http-client under the hood - but 'shading' to rename the packages so there's no clash)... works beautifully now (with slightly improved performance somehow) – Tom Feb 08 '16 at 10:32

0 Answers0