Scala .gitignore template
The Scala template ignores compiled classes and the target directory, plus the per developer state that the build server and language server keep inside the project.
At a glance
- Category
- Language
- Patterns in this template
- 9 rules
- Directories ignored
- 6 of the 9 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. The editor rules here cover language tooling, not the editor's own files.
- Typical companions
- An IDE template, since IntelliJ keeps its Scala state separately from Metals.
In detail
target is the output directory the build tool writes into, and in a multi project build there is one per subproject plus one at the root. It holds compiled classes, packaged artefacts, generated sources and the incremental compilation analysis. The rule is unanchored precisely so it catches all of them without you listing every module.
.bsp is the build server protocol directory. It contains connection files telling an editor how to start the build server for this project, including the absolute path to the launcher on the machine that generated them. Two developers with different installations will produce different files, so committing one guarantees a conflict.
.metals and .bloop are the language server and compile server working directories. Metals keeps its symbol index, semantic database and logs there; Bloop keeps generated build configuration in JSON, again full of absolute classpath entries. Both are rebuilt from the build definition when the editor next opens the project.
project/metals.sbt is a plugin file the language server writes into your build to enable its own integration. It is a tool detail rather than part of the project definition, and a teammate using a different editor has no use for it. project/project is the meta build's own output directory, one level up the recursive build definition that the build tool uses to compile the build itself.
.scala-build is the working directory used by the single file scripting tool, holding compiled output and resolved dependencies for scripts that are not part of a full build definition. Like the rest of the list it is derived state with a short lifetime.
Examples
*.class
*.log
target/
.bsp/
.metals/
.bloop/
project/metals.sbt
project/project/
.scala-build/9 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- target/ is unanchored, which is deliberate for multi module builds, but it will also match a source directory named target in an unrelated part of the repository.
- The rules here cover Metals but not IntelliJ, which keeps its Scala module configuration under .idea. Add the IntelliJ template if anyone on the team uses it.
- project/project is ignored but project itself is not, and it should not be: the build definition files inside it are source.
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.
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.
Kotlin .gitignore template
The Kotlin template covers the same class and archive output as Java, plus the .kotlin session directory the newer compiler writes into the project root.
R .gitignore template
The R template ignores saved workspaces, session history, rendered vignettes and check output, plus the .httr-oauth file that stores live access tokens.
Lua .gitignore template
A short template for a short toolchain: compiled bytecode from luac, packaged rock archives, and the local tree LuaRocks installs dependencies into.
Perl .gitignore template
The Perl template ignores the build library tree, generated metadata and coverage output, and its Makefile rule will also match a Makefile you wrote yourself.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS