233

I am working on a Java project with Gradle Wrapper (gradlew). I use Ubuntu Linux as my OS. When I run "gradle" it runs, and gives me information. But when I run "gradlew", it outputs as:

No command 'gradlew' found, did you mean:
Command 'gradle' from package 'gradle' (universe)
gradlew: command not found"

I did my research, I have the JDK, and I did sudo apt-get install gradle. How can I fix it?

The error is:

gradlew clean jpackage

Output:

bash: gradlew: command not found...
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hayden
  • 2,433
  • 2
  • 9
  • 9

20 Answers20

337

Linux and macOS

As noted in the comments, just running

./gradlew

worked for me. Adding the ./ tells it to look in the current directory since it isn't in the path.

If it stills doesn't work, run (as commented by Fadi)

chmod +x gradlew

And then try again

Windows PowerShell

.\gradlew
driconmax
  • 956
  • 1
  • 18
  • 32
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
140

The Gradle wrapper needs to be built. Try running gradle wrapper --gradle-version 2.13.

Remember to change 2.13 to your Gradle version number. After running this command, you should see new scripts added to your project folder. You should be able to run the wrapper with ./gradlew build to build your code.

Please refer to this guide for more information: Building Java Projects with Gradle

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alex Wilson
  • 1,773
  • 1
  • 12
  • 18
80

Running this Bash command works for me by running chmod 755 gradlew as sometimes file properties changed upon moving from one OS to another (Windows, Linux and Mac).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ayman Mahgoub
  • 4,152
  • 1
  • 30
  • 27
  • 1
    Your solution works, just to clarify, this command allows for execution file as a program (on Ubuntu 20.04 LTS) – Jacek Sawko Apr 26 '21 at 13:55
  • [chmod 755](https://chmodcommand.com/chmod-755/) = (chmod a+rwx,g-w,o-w) sets permissions so that, (U)ser / owner can read, can write and can execute. (G)roup can read, can't write and can execute. ***(O)thers*** can read, can't write and can ***execute***. – Peter Mortensen Feb 21 '23 at 04:44
47

If you are using Mac, try giving root access to gradlew by doing:

chmod +x ./gradlew
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pankaj Gaikar
  • 2,357
  • 1
  • 23
  • 29
30

From Mac,

Nothing is working except the following command:

chmod 777 gradlew

Then

./gradlew
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • gradlew needs permission on linux/mac, working for me after chmod 777 gradlew in root of my project. – Faisal Jul 05 '18 at 07:55
  • 3
    'chmod 777' makes gradlew world writable. This is a major security issue. Use 'chmod 555' instead. – Kelly Setzer Jun 17 '19 at 14:35
  • 1
    I'd recommend chmod 755 (-rwxr-xr-x). over 777 – notStan Jun 28 '19 at 10:07
  • [chmod 777](https://chmodcommand.com/chmod-777/): (chmod a+rwx) sets permissions so that, (U)ser / owner can read, can write and can execute. (G)roup can read, can write and can execute. ***(O)thers can read, can write and can execute***. – Peter Mortensen Feb 21 '23 at 04:51
  • [chmod 555](https://chmodcommand.com/chmod-555/): (chmod a+rwx,u-w,g-w,o-w) sets permissions so that, (U)ser / owner can read, can't write and can execute. (G)roup can read, can't write and can execute. (O)thers can read, can't write and can execute. – Peter Mortensen Feb 21 '23 at 04:53
  • [chmod 755](https://chmodcommand.com/chmod-755/): (chmod a+rwx,g-w,o-w) sets permissions so that, (U)ser / owner can read, can write and can execute. (G)roup can read, can't write and can execute. (O)thers can read, can't write and can execute. – Peter Mortensen Feb 21 '23 at 04:55
29

The same problem occurs to me...

I check the file wrx permissions with:

$ls -l ./gradlew -> -rw-rw-r-- (no execute permission)

So I use command $chmod +x ./gradlew and this problem is solved.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
shanwu
  • 1,493
  • 6
  • 35
  • 45
21

In addition to Suragch's answer:

Linux and macOS

./gradlew clean

Windows PowerShell

.\gradlew clean

Windows cmd

gradlew clean

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sanjeev Rao
  • 2,247
  • 1
  • 19
  • 18
12

You must have the Gradle wrapper available locally before using gradlew. To construct that

gradle wrapper # --gradle-version v.xy

Optionally, pass the Gradle version explicitly. This step produces the gradlew binary. And then you should be able to

./gradlew build
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rounak Datta
  • 442
  • 7
  • 10
7

For Ubuntu (Linux) users:

Doing bash ./gradlew build works, but ./gradlew build does not work.

For me, the issue was it was on the NTFS file system, and Linux does not let you execute a script from NTFS.

Try moving the code from NTFS to a Linux partition. Then ./gradlew build should work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abhishek
  • 97
  • 1
  • 6
7

If you are using Visual Studio Code with Flutter, you should find it in your app folder, under the android folder:

C:\myappFolder\android

You can run this in the terminal:

./gradlew signingReport
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
live-love
  • 48,840
  • 22
  • 240
  • 204
4

The first thing is you need to run the gradle task that you mentioned for this wrapper. Example:

gradle wrapper

After running this command, check your directory for the gradlew and gradlew.bat files. gradlew is the shell script file, and it can be used in Linux and macOS. gradlew.bat is the batch file for the Windows OS. Then run,

./gradlew build (Linux and Mac). It will work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sumukha H S
  • 141
  • 1
  • 6
2

Issue: Couldn't find gradlew at path jenkins

In my case, within the Jenkins CI for flutter project, I have to first run the flutter build app command, and then it automatically generated a gradlew file. And the above issue is resolved.

I put this command in my Jenkins file:

flutter build apk
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
maddy
  • 4,001
  • 8
  • 42
  • 65
2

In a Flutter project, don't forget to go to 'android' folder with 'cd android'. Then you can run a command like './gradlew build' or './gradlew clean' on it (macOS).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Florian K
  • 2,033
  • 1
  • 9
  • 21
1

If the answer marked as correct does not work, it is because you need to identify yourself as a super user.

sudo gradle wrapper --gradle-version 2.13

It worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anxo P
  • 759
  • 7
  • 12
1

I faced the same issue, but after some tries I found it was happening because I was trying to create build in Git Bash, instead of CMD with system administrator access.

If you create build with a command prompt, run as administrator. Then the build will get created.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Vishal Pachpande
  • 500
  • 5
  • 19
1

Instead of gradlew assembleRelease, use ./gradlew assembleRelease.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nikhil Jain
  • 244
  • 3
  • 7
1

If you are trying to run this command for a Flutter app, then go to the android folder first by cd android. And then use the command, and it should work.

cd android
./gradlew signingReport
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

I use IntelliJ IDEA and in Windows in the terminal I type:

gradlew.bat run

It is working for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
A Mo
  • 153
  • 8
  • 2
    Windows is *different*. For some reason, it always resolves executables in `.` as if it is in the path, even when it is very clearly not in the path. – Guss Dec 19 '17 at 12:04
0

I had to do dos2unix * in my current folder to make it work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ajay Menon
  • 127
  • 6
-2

Ubuntu

Error:

Command 'gradlew' not found, did you mean:
command 'gradle' from snap gradle (7.2)
command 'gradle' from deb gradle (4.4.1-13)
See 'snap info ' for additional versions.

Use this command:

./gradlew signingReport
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 27 '23 at 08:04