I'm working on a Jenkins plugin and including a jar as a dependency - but that jar is already included in the WEB-INF/lib directory of the main Jenkins webapp. This would be fine except my plugin needs version X and Jenkins includes version Y, and the api has changed between them so I can't use the old one, and Jenkins can't use the newer one.
The version I want is included inside my .hpi file but at runtime the version from jenkins/WEB-INF/lib gets picked up. I'm guessing due to classloaders I can't force it to pickup the version in my .hpi file, but wanted to check and see if anyone knows of a way to do this?
Thanks.
Per default Jenkins loads every jar from WEB-INF/lib, along with the contents of WEB-INF/classes after the classes and libraries of the core.
If you want to have your own libaries loaded before these (e.g. you want a newer version of velocity or an other library), you can configure your plugin to use a different classloader strategy by telling the hpi plugin in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<configuration>
<pluginFirstClassLoader>true</pluginFirstClassLoader>
</configuration>
</plugin>
</plugins>
</build>
For more details see the docs.