Skip to content
Latchkey

Jenkins "Loading libraries failed" - Fix Shared Library Load Errors

Jenkins resolved your shared library but could not load it - the Groovy in vars/ or src/ failed to compile, or a class it references is missing. The pipeline never starts because the library is loaded before any stage runs.

What this error means

The build fails at the very top with Loading libraries failed followed by a Groovy compilation error pointing at a file inside the library (vars/foo.groovy or src/com/...). The Jenkinsfile itself is fine; the failure is in the library code it pulled in.

Jenkins console
Loading libraries failed
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/vars/deployApp.groovy: 12: unable to resolve class com.example.Deployer
 @ line 12, column 5.
1 error

Common causes

Groovy compile error in the library

A syntax error, an unresolved class, or a bad import inside vars/ or src/ makes the whole library fail to compile, and Jenkins loads the entire library up front.

A referenced class is missing from src/

A var references a helper class under src/ that was never added, was renamed, or sits in the wrong package path, so the loader cannot resolve it.

How to fix it

Fix the Groovy that fails to compile

  1. Read the file and line in the error - it points inside the library, not the Jenkinsfile.
  2. Resolve missing classes by placing them under src/<package>/<Name>.groovy with a matching package declaration.
  3. Validate the library with its own unit tests (e.g. the Jenkins Pipeline Unit framework) before publishing the version.

Pin the library to a known-good version

Reference a tag that compiles cleanly rather than a moving branch that may carry a broken commit.

Jenkinsfile
@Library('platform-lib@v2.3.0') _
pipeline { agent any; stages { stage('CI') { steps { ciBuild() } } } }

How to prevent it

  • Unit-test shared libraries in their own repo before tagging a release.
  • Pin pipelines to library tags, not moving branches, for release builds.
  • Keep src/ package paths aligned with the class package declarations.

Frequently asked questions

Why does this fail before my first stage?
Shared libraries are loaded and compiled when the pipeline starts, before any stage runs. A compile error in the library therefore aborts the build at load time, not mid-stage.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →