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

I cleaned up the entire project by deleting local directories such as ~/.gradle , ~/.m2 ~./android and ~/workspace/project/.gradle and choosing File -> Invalidate Caches / Restart... in Android Studio. Now executing the ./gradlew leads to the following output:

 usr$ ./gradlew tasks Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain 

Needless to say, I deleted too much, the question is, how can it be restored again? Do you have any idea how to fix this?

+131
android-studio android-gradle gradle gradlew
Apr 22 '15 at 18:06
source share
19 answers

gradlew - gradlew wrapper executable - batch script for windows and shell script elsewhere. If you include the following lines in your build.gradle ,

 task wrapper(type: Wrapper) { gradleVersion = '4.1' } 

wrapper script added to your source folders. The shell script at startup loads a specific version of Gradle and executes it. By distributing packaging with your project, anyone can work with it without first installing Gradle. Moreover, assembly users are guaranteed to use the version of Gradle with which the assembly was calculated.

When uninstalling, you deleted something that gradlew depends on. You can only extract gradlew files from the source repository or, if you have gradle installed, run gradle wrapper to restore it.

ref: Gradle Wrapper

+95
Apr 22 '15 at 18:45
source share

In addition to @RaGe's answer, there may be a situation that I encountered when I had a global git ignore that ignored .jar files and therefore the gradle shell banner was never executed. So I got this error on the Jenkins server after trying /var/lib/jenkins/my_project/gradlew build . I had to explicitly force the jar to be added, and then commit:

 git add -f gradle/wrapper/gradle-wrapper.jar 
+176
Jul 25 '15 at 2:58
source share

In my case, it was a global .gitignore , as explained in @HankCa's answer .

Instead of forcibly adding a jar file that you need to remember in every Gradle project, I added an override to re-enable the jar shell in my global .gitignore :

 *.jar !gradle/wrapper/gradle-wrapper.jar 

This is useful to me, since I have many projects that use Gradle; Git will now remind me to include a jar of wrappers.

This override will work until no directories above gradle-wrapper.jar (such as gradle and wrapper ) are ignored - git will not gradle into ignored directories for performance reasons .

+33
Feb 01 '17 at 15:41
source share

The first execution worked for me:

  gradle wrapper 

After a successful build, I was able to run

 ./gradlew assembleRelease 

Note. To start gradle wrapper , first run brew install gradle . If the installation was successful, run gradle wrapper from the project root.

Source and thanks: http://gradle.org/docs/current/userguide/gradle_wrapper.html and https://stackoverflow.com/users/745574/rage

+25
Jun 27 '17 at 13:53 on
source share

In my case, I left the wrapper helper folder while copying the gradle folder and got the same error.

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

make sure you have the correct folder structure if you copy the shell from another location.

 β”œβ”€β”€ build.gradle
 β”œβ”€β”€ gradle
 β”‚ └── wrapper
 β”‚ β”œβ”€β”€ gradle-wrapper.jar
 β”‚ └── gradle-wrapper.properties
 β”œβ”€β”€ gradlew
 β”œβ”€β”€ gradlew.bat
 └── settings.gradle
+17
Nov 22 '17 at 19:35
source share

You may be missing gradle-wrapper.jar in the gradle/wrapper directory in your project.

You need to create this file using this script in the build.gradle file, as shown below,

 task wrapper(type: Wrapper) { gradleVersion = '2.0' // version required } 

and run the task:

 gradle wrapper 

With Gradle 2.4 (or higher), you can install the shell without adding a dedicated task:

 gradle wrapper --gradle-version 2.3 

OR

 gradle wrapper --gradle-distribution-url https://myEnterpriseRepository:7070/gradle/distributions/gradle-2.3-bin.zip 

All details can be found at this link.

+7
Jul 21 '17 at 6:48
source share

you can also copy the gradlew.bat file to the root folder and copy the gradlew-wrapper shell to the gradlew folder.

which work for me.

+4
May 03 '16 at 2:07
source share

In my case (using windows 10) gradlew.bat has the following lines of code in:

 set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% 

The APP_HOME variable is essentially the root folder with the gradient for the project, so if it gets messed up somehow, you will get:

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

This was ruined for me because there was an ampersand (&) in my project folder structure. For example, C: \ Test & Dev \ MyProject

So gradel tried to find the gradle -wrapper.jar file in the root folder C: \ Test (undoing everything after and including "&")

I found this by adding the following line below the installed line APP_HOME =% DIRNAME% above. Then ran the bat file to see the result.

 echo "%APP_HOME%" 

A few more β€œspecial characters” will appear that may break the path / directory.

+3
Nov 04 '16 at 19:20
source share

I followed the answers from above when I came across this. And if you have this problem, be sure to force the jar and properties files to be sent. After these two, I stopped getting this problem.

 git add -f gradle/wrapper/gradle-wrapper.jar git add -f gradle/wrapper/gradle-wrapper.properties 
+3
Feb 12 '19 at 22:11
source share

@HankCa solved the problem in my case too. I decided to change my dangerous **/*.jar ignores to understandable ones like src/**/lib/*.jar to avoid such problems in the future. Ignoring starting with ** / * is too dangerous, at least for me. And it's always a good idea to get an idea behind a .gitignore line just by looking at it.

+1
Sep 21 '16 at 9:49 on
source share

In my case, gradle -wrapper.jar is damaged after replacing a bunch of files. Return to the original solution to the problem.

+1
Dec 06 '17 at 9:42 on
source share

I fixed this problem with the following fix (maybe this will help someone):

Just check if there are names in the parent folders of your project folders with spaces or other forbidden characters. If so, take it away.

"C: \ Users \ someuser \ Test Projects \ testProj" - in this case, "Test Projects" should be "TestProjects".

+1
Mar 26 '18 at 15:23
source share

I saw the same error, but in my case it was a new Git installation without LFS. The repository in question was configured with LFS, and the gradle-wrapper.jar file was in LFS, so it contained only a pointer to the LFS server. The solution was simple, just run:

 git lfs install 

And the fresh clone did the trick. I suppose git lfs pull or just git pull could help too, but the person with the problem decided to make a new clone instead.

+1
Aug 19 '19 at 15:47
source share

On Gradle 5.x, I use:

 wrapper { gradleVersion = '5.5.1' } 
+1
Aug 22 '19 at 13:03
source share

In my case, I deleted the gradlew and gradle folders from the project. Restart clean build tasks through Run Gradle Task from the Gradle Projects window in intellij.

enter image description here

0
May 6 '18 at 12:45
source share

For Gradle 5+ version, this command solved my problem:

gradle wrapper

https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:adding_wrapper

0
Mar 18 '19 at 13:41
source share

if this is a new project, delete the existing folder and run $ npm install [CN00] act-native-cli

check that it works without errors

0
Apr 30 '19 at 20:13
source share

I installed git lfs on my machine and cloned the repository again, then it worked.

0
Jul 17 '19 at 12:50
source share

In similar circumstances, on our build server, I blocked all jar files in my .gitignore file, and gradle / wrapper / gradle-wrapper.jar was not sent to the build server. It might be worth checking if this jar is and whether it is correct.

0
Jul 18 '19 at 11:03
source share



All Articles