gradle-completion icon indicating copy to clipboard operation
gradle-completion copied to clipboard

./gradlew autocompletion gives an error

Open gayanper opened this issue 1 year ago • 6 comments

When trying to autocomplete when using the wrapper in the project ./gradlew it gives the following error

./gradlew _gradle:95: command not found: gradlew

This is on OS: MacOS 13 Arch: aarch64 Shell: zsh

gayanper avatar Mar 30 '23 08:03 gayanper

I am running Arch Linux with zsh and I have exactly the same problem.

When I switch to bash it works perfectly.

acsdev avatar Apr 12 '23 17:04 acsdev

I was able to fix this on Mac by adding . to my PATH as noted in the Troubleshooting section.

zsh completion using ./gradlew may not work on Linux if you don't have . on your $PATH, so I recommend adding it in your ~/.zshrc file:

jdrider avatar Jul 03 '23 20:07 jdrider

I was able to fix this on Mac by adding . to my PATH as noted in the Troubleshooting section.

zsh completion using ./gradlew may not work on Linux if you don't have . on your $PATH, so I recommend adding it in your ~/.zshrc file:

@gayanper did this work for you?

kworth avatar Mar 18 '24 19:03 kworth

@kworth Yes the suggestion works like a charm

gayanper avatar Mar 26 '24 18:03 gayanper

Not a great idea, that opens you up to malicious code. Eg I could drop an executable called "ls" and your "." in the path would execute that one instead the one in /bin/ls

wwadge avatar Apr 08 '24 05:04 wwadge

To anyone still struggling with this issue, I think I've come up with a solution that works and partially addresses wwadge's concerns:

# Gradle gradlew completion support
gradlew() {
    PATH=$PATH:$(pwd) ./gradlew "$@"
}

This way the current directory is only in path in the scope of the gradlew call not globally (so if you happen to have an executable called "ls" it's not going to be used if you type "ls" in your terminal). However, if gradlew itself attempts to use executable "x" that happens to be in your current directory then it will probably cause problems. Also (correct me if i'm wrong), if gradlew tries to add to PATH (which it should never do anyway) then it will end up including the current directory there too.

eslam-allam avatar Aug 07 '24 10:08 eslam-allam