gradle-completion
gradle-completion copied to clipboard
./gradlew autocompletion gives an error
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
I am running Arch Linux with zsh and I have exactly the same problem.
When I switch to bash it works perfectly.
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:
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 Yes the suggestion works like a charm
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
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.