Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

ErrorError: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

Short answer

The gradlew script starts Java with gradle/wrapper/gradle-wrapper.jar, and that JAR does not exist or is damaged. Typical causes are a .gitignore rule for *.jar or an incomplete copy. Regenerate the wrapper with an installed Gradle and commit the JAR.

  • Applies to Gradle 8.x, Gradle 9, Git 2.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check that the wrapper JAR exists and is not empty.

    ls -l gradle/wrapper/
  2. 2Match what you see, then jump to its fix

    1. 1gradle/wrapper has only gradle-wrapper.propertiesgradle-wrapper.jar is missing because Git ignores jar filesFix
    2. 2The same error appears although gradle-wrapper.jar is in placeThe JAR is present but damaged or from a bad copyFix

What does the error look like?

  • Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
  • Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain

Cause 1 of 2

gradle-wrapper.jar is missing because Git ignores jar files

1Check

A global or project .gitignore with *.jar keeps the JAR out of the repository, so a clone lacks it.

git check-ignore -v gradle/wrapper/gradle-wrapper.jar
git ls-files gradle/wrapper

2Fix

Add an exception rule for the wrapper JAR, regenerate it, and commit. Gradle's documentation says to put the JAR in version control.

# .gitignore
!gradle/wrapper/gradle-wrapper.jar

3Verify

The JAR is tracked.

git add -f gradle/wrapper/gradle-wrapper.jar
git ls-files gradle/wrapper

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 2

The JAR is present but damaged or from a bad copy

1Check

A damaged or incompletely copied JAR fails to load. Compare its SHA-256 with the published checksum for your Gradle version.

ls -l gradle/wrapper/gradle-wrapper.jar
shasum -a 256 gradle/wrapper/gradle-wrapper.jar

2Fix

Regenerate it. With a Gradle installed, run the wrapper task from the project root, then run it once more so the JAR and scripts are both refreshed.

gradle :wrapper
./gradlew :wrapper

3Verify

Gradle starts and prints its version.

./gradlew --version

Confirmed by docs.gradle.org

Did this fix it?

How do I stop it coming back?

  • Keep all four wrapper files in Git and add a CI step that fails if gradle-wrapper.jar is untracked.
  • Check the wrapper JAR checksum against Gradle's published list when it comes from outside your team.
  • Update the wrapper with the wrapper task, not by copying files from another project.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

./gradlew will not run: permission denied

zsh: permission denied: ./gradlew

The gradlew script has lost its executable bit, usually after a zip download, a Windows checkout or a copy to another disk.

3 causes, each with a fix

Mobile apps

Android app crashes because the Apache HTTP classes are missing

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.