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.

Open in generator Open with Java, Kotlin, Android, JetBrains

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

PatternWhat it ignores and why
.gradleGradle 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.propertiesWrapper 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.gradletasknamecacheGUI and task cachesGradle GUI settings and the task name cache used for shell completion.
.project.classpathEclipse-generated filesProject files that Eclipse Buildship generates from the Gradle configuration. They can be recreated from the build script at any time.

Practical notes

Original template

Gradle.gitignore9 rules
.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

Often used together

More template explanations