Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala on IntelliJ with Git: How should the .gitignore look like?

Note: This question is specific to Scala projects. I want to have Scala compile and run successfully from inside IntelliJ without any prior configuration.

I have created a test project containing Scala examples using IntelliJ IDEA and published it to GitHub.

The project structure looks like this:

Project Structure

My current .gitignore looks like this:

*.class
*.log
target/
.idea/
project/

This results in a repository that looks like this:

GitHub repository structure

Now for what I am trying to do:

Having Scala example code is cool, but I want to also use this project as a template for Scala projects with IntelliJ.

So, how should I best change my .gitignore file, so whenever I clone the project, I can open it with IntelliJ and have everything in working order? This, of course, excludes target directories, so I need to recompile the project whenever I clone it.

like image 800
Markus Appel Avatar asked Mar 12 '18 12:03

Markus Appel


People also ask

Where should I put Gitignore in IntelliJ?

gitignore file in the VCS root directory, you can right-click anywhere in the Project window, choose New | File and type . gitignore in the New File dialog.

How do I add files to Git ignore in IntelliJ?

In project view dialog, right click on any file / directory to add that file or directory to . gitignore for the project. If a . gitignore file does not exist for the project, it will be created.

Should .idea be ignored?

idea folder should be ignored, and if that's the case, it would automatically create a . gitignore file with the line .

How do I set Git credentials in IntelliJ?

In the Settings/Preferences dialog Ctrl+Alt+S , select Appearance and Behavior | System Settings | Passwords on the left. Select how you want IntelliJ IDEA to process passwords for Git remote repositories: In native Keychain: select this option to use native Keychain to store your passwords.


1 Answers

Assuming that you're using SBT to build your project in IntelliJ, you should filter out the following directories:

project/target/
target/

(Actually, just adding target/ filters both out.)

These directories contain SBT output generated from your sources, and should not be placed under version control.

If everyone working on your project is to use IntelliJ while working on the code, then you should add all of the ./.idea directory with the following exceptions:

.idea/.name
.idea/libraries/
.idea/modules/
.idea/modules.xml
.idea/scala_compiler.xml
.idea/tasks.xml
.idea/workspace.xml
.idea_modules/

(You might also want to consider adding .idea/sbt.xml to this list. It has some redundant information from SBT, but some IntelliJ SBT configuration settings as well. Up to you...)

These files and directories either contain information gleaned by IntelliJ from SBT (and are, therefore, redundant) or contain machine- and/or user-specific information which will create problems if checked out on a different machine or by a different user.

If SBT is the primary build tool, and people can use any IDE they like, it would probably be better to ignore the entire .idea directory instead.

like image 200
Mike Allen Avatar answered Oct 21 '22 04:10

Mike Allen