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:
My current .gitignore
looks like this:
*.class
*.log
target/
.idea/
project/
This results in a repository that looks like this:
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.
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.
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.
idea folder should be ignored, and if that's the case, it would automatically create a . gitignore file with the line .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With