• Stars
    star
    966
  • Rank 45,463 (Top 1.0 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Gradle tab completion for bash and zsh

gradle-completion

Bash and Zsh completion support for Gradle.

This provides fast tab completion for:

  • Gradle tasks for the current project and sub-projects
  • Gradle CLI switches (e.g. --parallel)
  • Common Gradle properties (e.g. -Dorg.gradle.debug)

It also handles custom default build files, so rootProject.buildFileName = 'build.gradle.kts' is supported.

See instructions for bash or for zsh, then consider optional additional configuration.

Here's a demo for the gradle project itself: Completion demo

Installation for Zsh 5.0+

Install via Homebrew

brew install gradle-completion

# Ensure /usr/local/share/zsh/site-functions is on $fpath. You should get a result from the following
echo $fpath | grep "/usr/local/share/zsh/site-functions"

Install as oh-my-zsh plugin

Download and place the plugin and completion script into your oh-my-zsh plugins directory.

git clone https://github.com/gradle/gradle-completion ~/.oh-my-zsh/plugins/gradle-completion

Add gradle-completion to the plugins array in your '.zshrc' file.

plugins+=(gradle-completion)

Install manually

Download and place _gradle on your $fpath. I recommend $HOME/.zsh/gradle-completion:

git clone https://github.com/gradle/gradle-completion ~/.zsh/gradle-completion

Add the following do your '.zshrc' file:

echo "\nfpath=($HOME/.zsh/gradle-completion \$fpath)" >> ~/.zshrc

Start a new terminal session. You may need to disable the gradle plugin for oh-my-zsh.

(Optional) Manual Completion Cache Initialization

Completion cache initialization happens the first time you invoke completion, and usually takes a few seconds, depending on the size of your project. You can manually initialize the cache and avoid interrupting your development mojo by running:

cd path/to/your-project
source ~/.zsh/gradle-completion/_gradle 1>&2 2>/dev/null; __gradle-completion-init

Installation for Bash 3.2+

Install via Homebrew

brew install gradle-completion

# Source completion scripts from bash-completion in your bash profile
echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >> ~/.bash_profile

# Load changes to bash profile
source ~/.bash_profile

Install manually

Download 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:

mkdir $HOME/bash_completion.d
curl -LA gradle-completion https://edub.me/gradle-completion-bash -o $HOME/bash_completion.d/gradle-completion.bash

NOTE: Ensure bash-completion 1.2+ is installed using your favorite package manager or by following the bash-completion installation instructions.

Add the following to your .bash_profile (macOS) or .bashrc (Linux) file:

source $HOME/bash_completion.d/gradle-completion.bash

Start a new terminal session.

(Optional) Manual Completion Cache Initialization

Completion cache initialization happens the first time you invoke completion, and usually takes a few seconds, depending on the size of your project. You can manually initialize the cache and avoid interrupting your development mojo by running:

cd path/to/your-project
__gradle-completion-init

Additional Configuration

Excluding build scripts from UP-TO-DATE check

Tab completion checks known build scripts to see if they've been changed and refreshes the task cache if so. You can exclude build scripts from this check (and speed up completion) by specifying:

# Default is `"/(build|integTest|out)/"`
export GRADLE_COMPLETION_EXCLUDE_PATTERN="/(build|integTest|samples|smokeTest|testFixtures|templates|out|features)/"
# Essentially turn off checking for changed scripts
export GRADLE_COMPLETION_EXCLUDE_PATTERN="gradle"

Completion cache

One can manually (re)generate the completion cache by invoking __gradle-completion-init after the completion script has been sourced. This graciously avoids an unexpected cache build when invoking completion.

The build script cache is invalidated if any *.gradle or *.gradle.kts files change. However, these completion scripts do not search for new build scripts every time completion is invoked, because that would make completion ~20x slower (unless you have so really good ideas on this).

By default, the build script cache is invalidated every 3 weeks (30240 minutes). You can configure this value by exporting a new value for $GRADLE_CACHE_TTL_MINUTES:

export GRADLE_CACHE_TTL_MINUTES=$(expr 1440 \* number_of_days_you_want)

Implicit Tasks

Gradle allows you to access tasks of subprojects from the project root implicitly. For example, given these tasks:

:foo
:help
:bar:baz

You can execute gradle baz from the project root and it will execute :bar:baz.

gradle-completion will not tab complete these tasks by default because it adds a significant number of completion options, which may not be what you want and negatively impacts completion speed.

To allow completion of implicit tasks, set $GRADLE_COMPLETION_UNQUALIFIED_TASKS=true:

export GRADLE_COMPLETION_UNQUALIFIED_TASKS="true"

You may need to invalidate the cache using the cache config above or by executing touch build.gradle.

Troubleshooting

If zsh completion isn't working, first try checking your $fpath with echo $fpath.

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:

export PATH=".:$PATH"

HEADS UP: If you get an error 'parse error near `]]"', please upgrade zsh. zsh 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.

If zsh completion reports "Generating Gradle task cache..." every time, the zsh completion cache may be disabled. Enable it by adding the following to your ~/.zshrc file:

zstyle ':completion:*' use-cache on

Contributing

See the contributing guide.

Acknowledgements

Bash completion is inspired by Nolan Lawson's Gradle tab completion for bash.

Zsh completion is an improved version of zsh's built-in Gradle completion.

Current improvements over built-in support:

  • Subproject tasks are completed
  • Gradle CLI options are current as of Gradle 6.4
  • Common Gradle properties are completed
  • Handles default build file as specified in settings.gradle
  • ~20x faster completion speed for medium to large projects
  • Completion cache updates in the background after first invocation

More Repositories

1

gradle

Adaptable, fast automation for all
Groovy
15,973
star
2

kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
Kotlin
3,705
star
3

gradle-profiler

A tool for gathering profiling and benchmarking information for Gradle builds
Java
1,279
star
4

gradle-build-action

Execute your Gradle build and trigger dependency submission
645
star
5

android-cache-fix-gradle-plugin

Gradle plugin that fixes Android build caching problems.
Groovy
440
star
6

wrapper-validation-action

Gradle Wrapper Validation Action
252
star
7

oreilly-gradle-book-examples

Java
249
star
8

test-retry-gradle-plugin

Gradle plugin to retry tests that have failed to mitigate test flakiness.
Groovy
199
star
9

native-samples

Samples of modern build automation for native languages with Gradle
Java
148
star
10

gradle-build-scan-quickstart

An example project to experience the Build Scan® service of Gradle Enterprise with Gradle builds.
Kotlin
132
star
11

native-platform

Java bindings for various native APIs
Java
111
star
12

foojay-toolchains

Java Toolchain Resolve Plugin based on the foojay DiscoAPI
Kotlin
95
star
13

gradle-native

The home of Gradle's support for natively compiled languages
91
star
14

build-tool-training-exercises

Exercises for live gradle.com/training sessions
Java
87
star
15

gradle-enterprise-build-validation-scripts

Executable scripts to assist in validating that your Gradle and Maven builds are in an optimal state in terms of maximizing work avoidance when using Develocity.
Shell
70
star
16

github-dependency-graph-gradle-plugin

Gradle Plugin for Extracting Dependency Information to send to GitHub
Groovy
69
star
17

develocity-build-config-samples

Code samples that demonstrate how to customize your Develocity build configuration using Gradle, Maven, Bazel or sbt
Java
62
star
18

actions

A collection of GitHub Actions to accelerate your Gradle Builds on GitHub
TypeScript
58
star
19

playframework

Gradle Play Support
Java
47
star
20

guides

The Gradle Guides at https://guides.gradle.org.
Java
47
star
21

gradle-site-plugin

Kotlin
42
star
22

wrapper-upgrade-gradle-plugin

Gradle plugin that detects and updates Gradle and Maven wrappers to the latest Gradle and Maven version.
Java
39
star
23

kotlin-dsl-docs

Generates Kotlin DSL API reference
Kotlin
37
star
24

build-tool-roadmap

Gradle Build Tool roadmap
35
star
25

common-custom-user-data-gradle-plugin

Gradle plugin that enhances published build scans by adding a set of tags, links and custom values that have proven to be useful for many projects building with Develocity.
Java
35
star
26

gradle-talks

A javascript based custom slide and build framework for presentations. Many of the Gradle engineers have been using this for their presentations. Those presentations are part of this repo and can be found in the talks directory.
Ruby
35
star
27

exemplar

Discover and verify code samples and services
Java
34
star
28

gradle2kts

Gradle Groovy to Gradle Kotlin conversion tool - discontinued spike
Kotlin
34
star
29

gradle-checksum

A Gradle plugin for creating checksums for files in your build.
Groovy
31
star
30

kotlin-dsl-conventions

Gradle Kotlin DSL conventional plugins
Kotlin
22
star
31

maven-build-scan-quickstart

An example project to experience the Build Scan® service of Develocity with Maven builds.
Java
20
star
32

bazel-comparison

20
star
33

declarative-gradle

Declarative Gradle is a project targeting better isolation of concern and expressing any build in a clear and understandable way
Java
18
star
34

develocity-oss-projects

18
star
35

performance-comparisons

A set of synthetic projects used to benchmark Gradle against other build tools
16
star
36

gradle-java-modules

A (former) place for experimenting with Java 9's module system. Gradle officially supports Java Modules since version 6.4
Java
16
star
37

cc-hackathon-2022

Configuration Cache Hackathon 2022
15
star
38

.github

Maintains all of the default policies for the Gradle organization
14
star
39

perf-enterprise-large

A large Java based build to use when benchmarking and profiling Gradle
Groovy
14
star
40

gradle-enterprise-export-api-samples

A repository of samples that demonstrate how to use the Gradle Enterprise Export API.
14
star
41

gradle-jdocbook

A Gradle plugin for jdocbook
Groovy
13
star
42

multi-project-composite-gradle-plugins-builds

Multi-project build using composite Gradle plugins
Kotlin
12
star
43

develocity-api-samples

A repository of samples that demonstrate how to use the Develocity API.
Java
12
star
44

webinar-getting-started-with-the-gradle-kotlin-dsl

Webinar - Getting Started with the Kotlin DSL
Kotlin
12
star
45

gradle-distributions

Repository for Gradle Build Tool distributions downloads
12
star
46

gcc2speedscope

Space usage analysis for the Gradle configuration cache via speedscope
Kotlin
12
star
47

speed-challenge

Instructions and overview for the Gradle and Maven Speed Challenge event
11
star
48

cucumber-companion

Maven & Gradle plugins providing convenient support for running Cucumber test directly from Maven/Gradle
Groovy
11
star
49

imaginate

Using the Kotlin language for production, test and build makes it easier for everyone to work with your software code base. Let’s go 100% Kotlin!
Kotlin
11
star
50

plugin-portal-requests

Gradle Plugin Portal issues and requests.
11
star
51

continuous-delivery-jump-start

Sample application used for training "Continuous Delivery Jump Start"
Java
11
star
52

build-analysis-demo

Build data analysis applications
Kotlin
10
star
53

santa-tracker-performance

Performance tests for Santa Tracker Android project
Shell
9
star
54

gradle-org-conventions-plugin

Java
9
star
55

perf-android-large-2

Another large Android build for performance experiments
9
star
56

gradle-hello-world-plugin

Groovy
9
star
57

gradle-issue-reproducer

Template repository for providing Gradle issue reproducers
9
star
58

tooling-commons

A small layer on top of the Gradle Tooling API that provides the Tooling Client and other convenience useful for IDE integration.
Java
9
star
59

develocity-testing-annotations

Common annotations for Develocity and Test Retry
Java
8
star
60

gradle-profiler-plugin

Java
8
star
61

jfr-polyfill

A polyfill for JDK Flight Recorder (JFR) to avoid errors on JDKs that don't support JFR yet
Java
8
star
62

configuration-cache-report

Kotlin
7
star
63

gradle-benchmark-base

Base scenarios for Gradle Profiler to benchmark Gradle builds
7
star
64

common-custom-user-data-maven-extension

Maven extension that enhances published build scans by adding a set of tags, links and custom values that have proven to be useful for many projects building with Develocity.
Java
7
star
65

bt-dev-prod-data-collector

Data collector for Gradle Build Tool Developer productivity metrics
Kotlin
7
star
66

gradle-hazelcast-plugin

Groovy
6
star
67

gradle-enterprise-build-optimization-experiments

Self-guiding experiments to optimize the performance of your Gradle and Maven builds with Gradle Enterprise.
6
star
68

gradle-rules-configuration-workshop

6
star
69

maven-build-cache-unstable-inputs-samples

An example project containing a build with unstable inputs
Java
6
star
70

gradle-project-templates

Learning day experiment: project init templates for Gradle
Java
5
star
71

source-resolution-demo

Java
5
star
72

greeting-plugin-example

Java
5
star
73

gradle-dependency-constrain

Java
5
star
74

develocity-bamboo-plugin

Develocity plugin for Bamboo
Java
4
star
75

community

Gradle Community content
HTML
4
star
76

stable-plugins-dsl

Getting the plugins {} DSL block out of incubation
Java
4
star
77

github-actions

Shared Github Actions
TypeScript
3
star
78

ide-smoke-tests

Java
3
star
79

gradle-all

A composite build that includes all the pieces of Gradle
Kotlin
3
star
80

ge-export

Java
3
star
81

webinar-dep-mgmt-part-1

Kotlin
3
star
82

develocity-gitlab-templates

GitLab CI/CD templates to automatically connect Gradle/Maven builds to Develocity
3
star
83

integrations

A repository for Gradle Integrations and the related knowledge base
3
star
84

gradle-performance

Gradle performance benchmarks using the Gradle build tool itself
Shell
3
star
85

provider-api-migration-testbed

A testbed to try out mitigation strategies for the provider API migration
Kotlin
3
star
86

gradle-model-vis

JavaScript
3
star
87

perf-native-large

A Place to Profile Particularly Prickly Projects
C
3
star
88

gradle-groovy-all

Replacement for groovy-all.jar discontinued in Groovy 2.5. This is intended to be used with Gradle only.
Kotlin
3
star
89

apachecon2021

Instructions and code repository for the ApacheCon 2021 Gradle Virtual Booth Event
2
star
90

kotlin-relocation-test

Cache relocatability test for Kotlin using Spek
Groovy
2
star
91

perf-android-local-repo

Java
2
star
92

api-evolution-demo

Demo of API evolution tricks
Java
2
star
93

Compilation-Avoidance-Experiment

A sample project for running comparative performance tests on build tools
Java
2
star
94

webinar-gradle-6

Webcast: What's New In Gradle 6.0?
Kotlin
2
star
95

ge-customer-support-zendesk-theme

Our custom zendesk theme used for support.gradle.com
Handlebars
2
star
96

build-tool-issue-automation-actions

Actions for Github issue automation
JavaScript
2
star
97

gradle-20388-multiple-toml

Example for solving gradle issue #20388
Kotlin
2
star
98

native-samples-cpp-library

A C++ library referenced by the Gradle C++ source dependencies samples
C++
2
star
99

impact_analysis

2
star
100

model-app

Java
2
star