• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

CONTRIBUTING.mdH A D20-Feb-20194.7 KiB10864

LICENSEH A D20-Feb-20191 KiB2016

README.mdH A D20-Feb-20196.8 KiB180131

_gradleH A D20-Feb-201922.7 KiB399366

gradle-completion.bashH A D20-Feb-201915.5 KiB376311

README.md

1# gradle-completion
2Bash and Zsh completion support for [Gradle](https://gradle.org).
3
4This provides _fast_ tab completion for:
5
6 * Gradle tasks for the current project and sub-projects
7 * Gradle CLI switches (e.g. `--parallel`)
8 * Common Gradle properties (e.g. `-Dorg.gradle.debug`)
9
10It also handles custom default build files, so `rootProject.buildFileName = 'build.gradle.kts'` is supported.
11
12See instructions [for bash](https://github.com/gradle/gradle-completion/blob/master/README.md#installation-for-bash-32) or [for zsh](https://github.com/gradle/gradle-completion/blob/master/README.md#installation-for-zsh-50), then consider optional [additional configuration](https://github.com/gradle/gradle-completion/blob/master/README.md#additional-configuration).
13
14Here's a demo for the gradle project itself:
15![Completion demo](gradle-completion-4.0.gif)
16
17## Installation for Zsh 5.0+
18
19### Install via [Homebrew](https://brew.sh)
20
21```
22brew install gradle-completion
23
24# Ensure /usr/local/share/zsh/site-functions is on $fpath. You should get a result from the following
25echo $fpath | grep "/usr/local/share/zsh/site-functions"
26```
27
28### Install manually
29
30Download and place `_gradle` on your `$fpath`. I recommend `$HOME/.zsh/gradle-completion`:
31```
32git clone git://github.com/gradle/gradle-completion ~/.zsh/gradle-completion
33```
34
35Add the following do your '.zshrc' file:
36```
37echo "\nfpath=($HOME/.zsh/gradle-completion \$fpath)" >> ~/.zshrc
38```
39
40Start a new terminal session. You may need to disable the `gradle` plugin for `oh-my-zsh`.
41
42#### (Optional) Manual Completion Cache Initialization
43Completion cache initialization happens the first time you invoke completion,
44and usually takes a few seconds, depending on the size of your project. You can
45manually initialize the cache and avoid interrupting your development mojo by
46running:
47
48```bash
49cd path/to/your-project
50source ~/.zsh/gradle-completion/_gradle 1>&2 2>/dev/null; __gradle-completion-init
51```
52
53## Installation for Bash 3.2+
54
55### Install via [Homebrew](https://brew.sh)
56
57```
58brew install gradle-completion
59
60# Source completion scripts from bash-completion in your bash profile
61echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >> ~/.bash_profile
62
63# Load changes to bash profile
64source ~/.bash_profile
65```
66
67### Install manually
68
69Download and place `gradle-completion.bash` in your `bash_completion.d` folder, usually `/etc/bash_completion.d`, `/usr/local/etc/bash_completion.d`, or `$HOME/bash_completion.d`:
70```
71mkdir $HOME/bash_completion.d
72curl -LA gradle-completion https://edub.me/gradle-completion-bash -o $HOME/bash_completion.d/gradle-completion.bash
73```
74
75NOTE: Ensure `bash-completion` 1.2+ is installed using your favorite package manager or by following the [bash-completion installation instructions](https://github.com/scop/bash-completion/blob/master/README.md#installation).
76
77Add the following to your `.bash_profile` (macOS) or `.bashrc` (Linux) file:
78```
79source $HOME/bash_completion.d/gradle-completion.bash
80```
81
82Start a new terminal session.
83
84#### (Optional) Manual Completion Cache Initialization
85Completion cache initialization happens the first time you invoke completion,
86and usually takes a few seconds, depending on the size of your project. You can
87manually initialize the cache and avoid interrupting your development mojo by
88running:
89
90```bash
91cd path/to/your-project
92__gradle-completion-init
93```
94
95## Additional Configuration
96
97#### Excluding build scripts from UP-TO-DATE check
98Tab completion checks known build scripts to see if they've been changed and refreshes the task cache if so.
99You can exclude build scripts from this check (and speed up completion) by specifying:
100
101```bash
102# Default is `"/(build|integTest|out)/"`
103export GRADLE_COMPLETION_EXCLUDE_PATTERN="/(build|integTest|samples|smokeTest|testFixtures|templates|out|features)/"
104# Essentially turn off checking for changed scripts
105export GRADLE_COMPLETION_EXCLUDE_PATTERN="gradle"
106```
107
108#### Completion cache
109One can manually (re)generate the completion cache by invoking `__gradle-completion-init` after the
110completion script has been sourced. This graciously avoids an unexpected cache build when invoking
111completion.
112
113The build script cache is invalidated if any *.gradle or *.gradle.kts files change.
114However, these completion scripts do not search for new build scripts every time completion is invoked, because
115that would make completion ~20x slower (unless you have so really good ideas on this).
116
117By default, the build script cache is invalidated every 3 weeks (30240 minutes).
118You can configure this value by exporting a new value for `$GRADLE_CACHE_TTL_MINUTES`:
119```bash
120export GRADLE_CACHE_TTL_MINUTES=$(expr 1440 \* number_of_days_you_want)
121```
122
123#### Implicit Tasks
124Gradle allows you to access tasks of subprojects from the project root implicitly.
125For example, given these tasks:
126```
127:foo
128:help
129:bar:baz
130```
131
132You can execute `gradle baz` from the project root and it will execute `:bar:baz`.
133
134gradle-completion will not tab complete these tasks by default because it adds a
135significant number of completion options, which may not be what you want and
136negatively impacts completion speed.
137
138To allow completion of implicit tasks, set `$GRADLE_COMPLETION_UNQUALIFIED_TASKS=true`:
139
140```bash
141export GRADLE_COMPLETION_UNQUALIFIED_TASKS="true"
142```
143
144You may need to invalidate the cache using the cache config above or by executing `touch build.gradle`.
145
146## Troubleshooting
147If zsh completion isn't working, first try checking your `$fpath` with `echo $fpath`.
148
149zsh completion using `./gradlew` may not work on Linux if you don't have `.` on your `$PATH`,
150so I recommend adding it in your `~/.zshrc` file:
151```bash
152export PATH=".:$PATH"
153```
154
155> HEADS UP: If you get an error 'parse error near `]]"', please [upgrade zsh](http://stackoverflow.com/questions/17648621/how-do-i-update-zsh-to-the-latest-version).
156zsh 5.0.5 has a bug in script parsing that is fixed as of zsh 5.0.8. See issues #4 and #7 for more details.
157
158If zsh completion reports "Generating Gradle task cache..." every time, the zsh completion cache
159may be disabled. Enable it by adding the following to your `~/.zshrc` file:
160```bash
161zstyle ':completion:*' use-cache on
162```
163
164## Contributing
165
166See the [contributing guide](CONTRIBUTING.md).
167
168## Acknowledgements
169Bash completion is inspired by [Nolan Lawson's Gradle tab completion for bash](https://gist.github.com/nolanlawson/8694399).
170
171Zsh completion is an improved version of [zsh](https://github.com/zsh-users/zsh)'s built-in Gradle completion.
172
173Current improvements over built-in support:
174 - Subproject tasks are completed
175 - Gradle CLI options are current as of Gradle 5.2
176 - Common Gradle properties are completed
177 - Handles default build file as specified in settings.gradle
178 - ~20x faster completion speed for medium to large projects
179 - Completion cache updates in the background after first invocation
180