Git β€’ Languages & Frameworks

Java (Maven & Gradle) .gitignore Template

Java builds generate class files (*.class), packed archives (*.jar, *.war), and local build tool caches. This template supports Maven, Gradle, Eclipse, and IntelliJ IDEA.

.gitignore(38 lines)
1# Compiled class files
2*.class
3
4# Log files
5*.log
6
7# Package files
8*.jar
9*.war
10*.nar
11*.ear
12*.zip
13*.tar.gz
14*.rar
15
16# Virtual machine crash logs
17hs_err_pid*
18replay_pid*
19
20# Maven target directory
21target/
22pom.xml.tag
23pom.xml.releaseBackup
24pom.xml.versionsBackup
25pom.xml.next
26release.properties
27
28# Gradle build directory
29.gradle/
30build/
31!gradle/wrapper/gradle-wrapper.jar
32
33# IDE files
34.idea/
35*.iml
36.project
37.classpath
38.settings/

Key Rules & Why They Are Ignored

target/ & build/

Maven (`target/`) and Gradle (`build/`) compiled output directories.

!gradle/wrapper/gradle-wrapper.jar

Important: Keeps the Gradle wrapper JAR tracked so developers can run `./gradlew` without installing Gradle.

Already Committed Ignored Files? Purge from Git Cache

Adding a pattern to .gitignore does NOT delete files that were already tracked in previous commits. Run this command to remove them from tracking without deleting your local copies:

git rm -r --cached . && git add . && git commit -m "Untrack ignored files"

Frequently Asked Questions About Java .gitignore

Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

The Gradle wrapper allows developers and CI/CD pipelines to build the project immediately using `./gradlew` without needing a pre-installed Gradle binary on the host.