.gitignore Builder for Java / Maven / Gradle

Generate a .gitignore for Java projects with Maven or Gradle

Build a .gitignore for Java projects. Covers target/, build/, .gradle, *.class, .classpath, .project and IDE files for Maven, Gradle, Eclipse and IntelliJ — copy or download in your browser.

Why ignore the target/ and build/ folders?

Maven writes compiled output to target/ and Gradle writes to build/. Both are fully regenerated from your source on every build, so committing them adds noise and merge conflicts without any benefit.

A .gitignore builder tuned for Java projects built with Maven or Gradle. Pick your build tool and IDE, and the tool assembles the right ignore patterns for compiled output, dependency caches and editor settings into one labelled file.

How it works

Each toggle adds a curated block of patterns under a # Header comment. The build-output blocks ignore Maven’s target/ directory and Gradle’s build/ and .gradle/ cache, while keeping the wrapper jars so the pinned build-tool version stays in the repo. The compiled-output block ignores *.class files produced by javac, and the package block ignores generated *.jar, *.war and *.ear artifacts plus crash logs like hs_err_pid*.

What gets ignored

The Maven block excludes target/ and release backup files. The Gradle block excludes .gradle/ and build/ but negates the wrapper jar with !gradle/wrapper/gradle-wrapper.jar. The Eclipse and IntelliJ IDEA blocks ignore .classpath, .project, .settings/, .idea/ and *.iml so each developer keeps their own IDE configuration.

Tips

Place the file at the root of your repository so the rules apply to every module. Always commit your wrapper (gradlew / mvnw) so contributors and CI use the exact same build-tool version. If a derived file is already tracked, run git rm --cached <file> and commit before the ignore rule takes effect.