Maven .gitignore template
The Maven template ignores the target output directory and the several backup and state files the release plugin writes while a release is in progress.
At a glance
- Category
- Build Tool
- Patterns in this template
- 10 rules
- Directories ignored
- 1 of the 10 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes, along with an IDE template.
- Typical companions
- Java or Spring Boot, plus an IDE template and an OS template.
In detail
target is the only rule most projects will ever need. Everything the build produces lands there: compiled classes, generated sources, test reports, the packaged jar or war, and the dependency copies used at test time. It is derived entirely from the project object model and the sources, and it is rebuilt from scratch by a clean build.
The rest of the template exists because the release plugin is unusually messy. Preparing a release rewrites the project file to a release version, tags, then rewrites it again to the next development version, and it keeps backups at each step. pom.xml.tag, pom.xml.releaseBackup, pom.xml.versionsBackup and pom.xml.next are those backups.
release.properties is the state file that lets an interrupted release be resumed. If a release fails halfway, that file is how the plugin knows where it stopped, which makes it genuinely useful locally and completely meaningless to anyone else. Committing it can also confuse a later release attempt.
dependency-reduced-pom.xml is generated by the shade plugin when it builds an uber jar, holding a version of the project file with the shaded dependencies stripped out. buildNumber.properties comes from the build number plugin and .mvn/timing.properties is profiling output. None of the three appear unless the matching plugin is configured, so most projects will never create any of them.
The wrapper jar is where this template differs from its Gradle counterpart. It ignores .mvn/wrapper/maven-wrapper.jar rather than negating it, which reflects the newer wrapper that downloads the jar on first use instead of shipping it. On an older project that still commits the jar, remove that line, otherwise you will untrack the file a clone needs.
Examples
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar10 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- This template ignores the Maven wrapper jar, which is the opposite of what the Gradle template does. On a project that still commits its wrapper jar, remove the line before it untracks the file.
- target/ is unanchored, which correctly covers every module in a multi module build, and also matches a source directory named target if you have one.
- release.properties left over from a failed release can confuse the next attempt. Ignoring it is right, but delete the stale file rather than leaving it in place.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Java .gitignore template
What the Java .gitignore template ignores: compiled classes, packaged archives, crash dumps, and the negations that keep the Gradle wrapper jar tracked.
Spring Boot .gitignore template
The Spring Boot template covers both build tools at once and adds sections for three IDEs, which makes it broad but leaves application secrets uncovered.
Gradle .gitignore template
Six rules covering the Gradle cache and build directories, with negations that keep the wrapper jar and properties tracked because a clone needs both.
npm .gitignore template
This template ignores package-lock.json, which contradicts the current advice to commit the lockfile. Here is what the rest of it covers and what to change.
Yarn .gitignore template
The Yarn template ignores the .yarn directory's contents while negating five subdirectories, because which ones you keep depends on the install mode you use.
pnpm .gitignore template
The shortest package manager template, because pnpm keeps its content addressed store outside the project and links into it rather than copying packages.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
- GitHub Actions Generator Free online github actions generator - generate CI/CD workflow YAML files from templates