Gradle "Could not find or load main class org.gradle.wrapper.GradleWrapperMain" in CI
The gradlew script launches the JVM with the wrapper main class, which lives in gradle/wrapper/gradle-wrapper.jar. When that jar is absent from the checkout, the JVM cannot find the class and the build never starts.
What this error means
A ./gradlew step fails immediately with "Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain" and a "Caused by: java.lang.ClassNotFoundException".
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMainCommon causes
gradle-wrapper.jar was never committed
A .gitignore rule that ignores *.jar excluded the wrapper jar, so the repository has the scripts but not the jar CI needs.
A sparse or partial checkout skipped the wrapper
A shallow path-filtered checkout did not include gradle/wrapper/, so the jar is missing on the runner even though it exists in the repo.
How to fix it
Commit the wrapper jar
- Regenerate the wrapper locally so
gradle-wrapper.jaris present. - Force-add the jar past any
.gitignorerule and commit it. - Confirm
gradle/wrapper/gradle-wrapper.jaris in the repository.
gradle wrapper
git add -f gradle/wrapper/gradle-wrapper.jarCheck the wrapper out in CI
Ensure the checkout includes the wrapper directory and is not path-filtered to exclude it.
- uses: actions/checkout@v4
- run: ./gradlew buildHow to prevent it
- Keep
gradle/wrapper/gradle-wrapper.jarcommitted and not gitignored. - Add a
.gitignoreexception for the wrapper jar if*.jaris ignored. - Avoid path-filtered checkouts that drop the wrapper directory.