Error message "gradlew: command not found"
Asked Answered
H

20

243

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...
Hyperbolism answered 17/1, 2017 at 15:19 Comment(3)
Run ./gradlew. It isn't on your path but is an executable that is present in the root directory of the project you checkout.Drawbar
Read the documentation on the gradle wrapper, docs.gradle.org/current/userguide/gradle_wrapper.html.Penza
Using Windows: Solve my problem running command prompt as administratorBarbwire
H
145

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

Halden answered 17/1, 2017 at 15:25 Comment(0)
L
363

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
Lastditch answered 12/5, 2017 at 11:39 Comment(5)
first try "chmod +x gradlew" and then "./gradlew" if not workingAcetylate
for macOS catalina, "sudo bash ./gradlew" works for meEurythmics
no one can even assume that there might be no gradlew at the address ./Antananarivo
chmod +x gradlew has worked for meUncounted
To those who are confused about the chmod +x ./gradlew, the chmod +x part just makes the ./gradlew executable. You need to use this, just trying with sudo won't work.Escheat
H
145

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

Halden answered 17/1, 2017 at 15:25 Comment(0)
D
81

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).

Drastic answered 26/2, 2017 at 13:0 Comment(2)
Your solution works, just to clarify, this command allows for execution file as a program (on Ubuntu 20.04 LTS)Market
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.Naresh
F
49

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

chmod +x ./gradlew
Forth answered 11/4, 2019 at 6:51 Comment(0)
L
33

From Mac,

Nothing is working except the following command:

chmod 777 gradlew

Then

./gradlew
Lurlene answered 13/6, 2018 at 22:35 Comment(6)
gradlew needs permission on linux/mac, working for me after chmod 777 gradlew in root of my project.Ginkgo
'chmod 777' makes gradlew world writable. This is a major security issue. Use 'chmod 555' instead.Bedaub
I'd recommend chmod 755 (-rwxr-xr-x). over 777Customhouse
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.Naresh
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.Naresh
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.Naresh
C
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.

Countershading answered 21/7, 2018 at 16:28 Comment(0)
T
21

In addition to Suragch's answer:

Linux and macOS

./gradlew clean

Windows PowerShell

.\gradlew clean

Windows cmd

gradlew clean

Theophilus answered 27/3, 2019 at 16:27 Comment(1)
Thanks! after hours of lurking from macos environment, this fixed: ./gradlew cleanSchnapp
R
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
Roomy answered 16/7, 2020 at 9:24 Comment(1)
zsh: command not found: gradleAntananarivo
I
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.

Iniquity answered 3/7, 2019 at 7:21 Comment(3)
Works for RedHat 7 tooNatty
Pop_OS! here, worked. Though my filesystem is default ext4Unorganized
Re "Linux does not let you execute a script from NTFS.": Why not? Isn't it only a question of permissions (or how the partition is mounted)? What is special about NTFS?Naresh
Y
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
Yelmene answered 27/6, 2020 at 23:17 Comment(1)
this was the case for meWashburn
E
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.

Evermore answered 4/11, 2018 at 16:56 Comment(0)
A
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
Arietta answered 10/12, 2021 at 7:16 Comment(0)
B
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).

Briticism answered 9/5, 2022 at 10:35 Comment(0)
Y
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.

Yakut answered 12/3, 2019 at 14:23 Comment(0)
P
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.

Pickerel answered 29/1, 2020 at 16:14 Comment(0)
S
1

Instead of gradlew assembleRelease, use ./gradlew assembleRelease.

Saccharase answered 18/11, 2021 at 9:28 Comment(0)
I
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
Ivan answered 9/1, 2022 at 2:37 Comment(0)
F
0

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

gradlew.bat run

It is working for me.

Fringe answered 9/12, 2017 at 17:32 Comment(1)
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.Anthelmintic
S
0

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

Strew answered 27/1, 2022 at 18:32 Comment(0)
C
-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
Copro answered 25/1, 2023 at 16:47 Comment(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.Doretha

© 2022 - 2024 — McMap. All rights reserved.