github/gitignore · Gradle.gitignore
Gradle .gitignore Template Explained
How Gradle.gitignore ignores the .gradle and build folders while using negation patterns to restore build folders under src and the Gradle wrapper jar.
Gradle.gitignore is only 9 lines, but it uses negation patterns three times to precisely protect what must not be ignored. It is almost always used together with the Java or Kotlin template.
The Gradle wrapper (gradlew, gradle/wrapper/gradle-wrapper.jar, gradle-wrapper.properties) lets people who have not installed Gradle build with the same version, so it must be committed. The official Gradle documentation also advises putting the wrapper files under version control.
Rules explained
| Pattern | What it ignores and why |
|---|---|
.gradle | Gradle cacheThe folder that stores per-project task caches and file hashes. If deleted, it is recreated on the next build. |
**/build/!**/src/**/build/ | Build folders and exceptionsExcludes the build/ output folder of every module, but restores it if a package or folder that happens to be named build exists inside the source tree (src/). For example, it prevents src/main/java/com/example/build/ from being mistaken for build output and disappearing. |
!gradle-wrapper.jar!gradle-wrapper.properties | Wrapper protectionRe-includes the wrapper jar so that the *.jar rule from the Java or Kotlin template does not ignore it. Because git follows the last matching rule, this line only works if it comes after *.jar. |
gradle-app.setting.gradletasknamecache | GUI and task cachesGradle GUI settings and the task name cache used for shell completion. |
.project.classpath | Eclipse-generated filesProject files that Eclipse Buildship generates from the Gradle configuration. They can be recreated from the build script at any time. |
Practical notes
- In the generator, select Java (or Kotlin) first and Gradle afterward. If the order is reversed,
!gradle-wrapper.jarcomes first and*.jarignores the jar again after it. You can check by puttinggradle/wrapper/gradle-wrapper.jarinto the pattern tester. gradle.propertiesis not ignored. However, keep personal signing information or tokens in~/.gradle/gradle.propertiesin your home directory, not in the project file.local.properties(the Android SDK path) is not in this template, so for Android projects use the Android template as well.
Original template
Gradle.gitignore
.gradle**/build/!**/src/**/build/# Ignore Gradle GUI configgradle-app.setting# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)!gradle-wrapper.jar# Avoid ignore Gradle wrapper properties!gradle-wrapper.properties# Cache of project.gradletasknamecache# Eclipse Gradle plugin generated files# Eclipse Core.project# JDT-specific (Eclipse Java Development Tools).classpath
Templates from github/gitignore/Gradle.gitignore @356fd7b (2026-09-11) · CC0-1.0