gradle / gradle-completion

Gradle tab completion for bash and zsh
MIT License
1.02k stars 133 forks source link

Is it supposed to work if gradle is not installed system wide, and only the wrapper is available? #83

Closed DanielWeigl closed 4 years ago

DanielWeigl commented 4 years ago

Does it need a system-wide installed gradle, or should it also work if only the wrapper is available in the project dir?

Ive installed it (for zsh 5.7.1, with the oh-my-zsh way) and I dont have gradle installed system wide (I had previously had some negative experiences/accidently version mix ups, and so far everything works, with only the wrapper in each project dir installed)

if I try ./gradlew --<tab> it expands all available options, but ./gradlew <tab><tab> or ./gradlew :<tab><tab> never shows anything (no error, no completion, nothing).

If it needs a system wide gradle available, even if I use the wrapper, maybe an error "gradle not found" or add it to the readme.

eriwen commented 4 years ago

This will work with just the wrapper. It looks like the completion did not initialize (get the list of projects/tasks) successfully.

Could you run __gradle_completion_init to force initialization and try it? If it does not work. Could you look in ~/.gradle/completion/... and see if the files are there and if they're empty or populated?

DanielWeigl commented 4 years ago

Hi, thanks for your response.

I just tried it on a fresh installation (without global installed gradle):

In a Java project folder with gradlew in the current folder, "gradle-completion" not installed:

~/src/ # ./gradlew <tab><tab>
Der Befehl 'gradlew' wurde nicht gefunden, meinten Sie:
  Befehl 'gradle' aus dem deb gradle (4.4.1-8)
Versuche: sudo apt install <deb name>

(this is expected, the system wide zsh completion tries to run gradle which fails and ubuntu suggest to install it)

after installing "gradle-completion" (via zsh/oh-my-zsh) and starting a new shell:

~/src/ # ./gradlew <tab><tab>

(no output)

~/src/ # ./gradlew --<tab>
--build-file            -- Specifies the build file.
--cache                 -- Specifies how compiled build scripts should be cached.
--continue              -- Continues task execution after a task failure.
--daemon                -- Uses the Gradle daemon to run the build. Starts the daemon if not running.
--debug                 -- Log in debug mode (includes normal stacktrace).
--dry-run               -- Runs the builds with all task actions disabled.
...

(argument help works - which did not work before installing it)

running __gradle_completion_init does not return anything (no error, no output), but completion is still the same afterwards

find ~/.gradle/completion/ .gradle/completion
find: '/home/user/.gradle/completion/': No such file or directory
find: '.gradle/completion': No such file or directory

Can I somehow enable debug output/logging?

DanielWeigl commented 4 years ago

I just tried to make it reproduceable:

host#> docker run -it openjdk:8-jdk-stretch /bin/bash
docker/bash#> apt-get update && apt-get install -y zsh git
docker/bash#> sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
# now we are in a zsh shell
docker/zsh#> git clone git://github.com/gradle/gradle-completion ~/.oh-my-zsh/plugins/gradle-completion
docker/zsh#> echo "plugins+=(gradle-completion)" >> ~/.zshrc
docker/zsh#> zsh
docker/subzsh#> git clone https://github.com/jabedhasan21/java-hello-world-with-gradle.git  # just a random repo i found, that uses gradlew
docker/subzsh#> cd java-hello-world-with-gradle    
docker/subzsh#> ./gradlew <tab><tab>.... # nothing

(or in one command:

docker run -it openjdk:8-jdk-stretch /bin/bash -c "apt-get update && apt-get install -y zsh git && wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O ohmy.sh && chmod +x ohmy.sh && RUNZSH=no ./ohmy.sh && git clone git://github.com/gradle/gradle-completion ~/.oh-my-zsh/plugins/gradle-completion && echo 'plugins+=(gradle-completion)' >> ~/.zshrc && git clone https://github.com/jabedhasan21/java-hello-world-with-gradle.git && zsh"

)

DanielWeigl commented 4 years ago

Sorry - my error - ive added the plugins+=(gradle-completion) after the source $ZSH/oh-my-zsh.sh include, but it needs to be before it, so it gets correctly loaded... :man_facepalming:

now it works as expected :+1: - thx for the nice tool

haja commented 4 years ago

I just hit the same problem.

might want to state in the README that the plugin config needs to come before the source command?