IntelliJ idea and duplicate class issue - intellij-idea

The dev env unfortunately is such that it creates a duplicate java file in a hidden directory under the same original root for every .java file. This is just a backup mechanism and can't change it. Good thing is this hidden dir name is same. I have Excluded this dir name pattern in the Settings of Intellij IDEA community edition 10.x. Yet, IDE reports this class as a duplicate one. Usages/References as well.
Bonus Q: Is there an eclipse equivalent of Ctrl-O in my IDEA to quickly navigate to methods?

How exactly did you exclude it? It should be added to the list of ignored folders in Settings | File Types. If it doesn't work, file a bug.
Bonus Q: Is there an eclipse equivalent of Ctrl-O in my IDEA to quickly navigate to methods?
Already replied here and here. Use Ctrl+F12.

Related

IntelliJ different project settings based on used IDE

I have a Git repo with two directories:
backend (PHP/Laravel code)
frontend (TypeScript/Vue code)
I would like that backend is marked as excluded when the project is opened in WebStorm and frontend to be excluded when it is opened in PhpStorm.
This is to ensure that searches/indexing only happen for the files that I would actually edit in that specific IDE.
When I change the excluded directory it seems to automatically apply this to the other IDE as well. Is there some way to keep this setting separate?
Comments:
I intentionally have both frontend and backend in one repository.
Opening the subdirectories in their own IDEA projects does not seem
to be an option because the Git integration only works when the
project is in the root folder of the repository.
When I change the excluded directory it seems to automatically apply this to the other IDE as well.
It is expected. That's because the project settings are stored in the .idea subfolder. All IDEA-based IDEs use the same .idea settings format. So opening the same folder/project in different IDEs simply makes them use that already-made config (shared between IDEs).
Plus, both PhpStorm and WebStorm use the same module type ID (WEB_MODULE) and can have only 1 module in total in a project. IntelliJ IDEA and some other IDEs (like PyCharm for example) can work with projects that can have more than one module and of different types.
Is there some way to keep this setting separate?
Yes, with the help of a small workaround: you need to store .idea used by another IDE in another place. As simple as that.
The setup and steps:
Lets assume that you have your project in C:\Projects\MyProject.
Make a brand new empty project in another place, e.g. C:\Projects\IDEProjectsStore\MyProject-frontend. It will be used for a frontend.
Go to Settings/Preferences | Directories and remove an existing Content Root (which will be C:\Projects\IDEProjectsStore\MyProject-frontend from the previous step).
Add new Content Root instead -- point to the actual project (C:\Projects\MyProject from step #1)
Save and configure as needed.
What you will have now:
This frontend project will now have its settings stored in C:\Projects\IDEProjectsStore\MyProject-frontend\.idea while another (original project with backend) will have them in C:\Projects\MyProject\.idea.
Projects (project-specific IDE settings) are stored in 2 separate places while they both use the same folder with the code.
Basically: a project in the IDE's eyes is an .idea folder with a parent folder added as a Content Root by default. Our workaround keeps the second project in a different folder while sharing the same Content Root between them.
https://youtrack.jetbrains.com/issue/IDEA-170102/ -- that's a ticket that asks for a straightforward way of doing this.
I would like that backend is marked as excluded when the project is opened in WebStorm and frontend to be excluded when it is opened in PhpStorm.
Why do you need two IDEs for this?
In case if you do not know: PhpStorm = WebStorm + PHP + Database. You do not really need WebStorm here. Just install any missing plugins that come bundled with WebStorm.

How to add a file to version control in IntelliJ?

When I create a new file in IntelliJ IDEA, it gets automatically ignored by Subversion, no matter what, and it is impossible to commit the file. While in Spring Tool Suite all I need to do is right click and select Team>Add to version control in order to commit that new file. I have try several approaches with no success since many options are disabled.
When I create a new file in IntelliJ IDEA, it gets automatically ignored by Subversion
What do you mean by automatically? There is no any automatic rules - file is either configured as ignored, or not. Make sure there is no svn:ignore property set on the folder (probably not since other tools work).
Also, make sure nothing wrong is added to Settings | Version Control | Ignored Files. The description looks like you have the entire project or sources folder added there as ignored
Finally I found a solution: the problem was that a parent directory was being ignored by SVN, so I searched directory by directory starting with the current directory until I found a parent directory that had a configuration to ignore all directories, for this task I used tortoise, just right click and select TortoiseSVN>Properties look for ignored files and delete the directory you want to synchronize, if no you donĀ“t find the directory look for (*).

How to configure IntelliJ products WITHOUT editing files in bin?

I'd like to set some specific options in idea.vmoptions and idea.properties for IntelliJ IDEA 14, but I don't have access to those files in C:\Program Files\... (yes, that's Windows, don't troll ;)
Is there a folder in %UserProfile% or an environment variable I could set to read those files (both vmoptions and properties!) from elsewhere?
Please don't suggest to copy the whole IDEA folder elsewhere, there's a reason why I can't access it. I would be interested in a Linux solution too, the same would most likely work on Windows.
My Research
For Mac there're specific instructions at Increasing Memory Heap, but for Linux and Windows it's just filename which are trivial to find out anyway.
I also found IntelliJ IDEA files locations, but it says can be modified in IDEA_HOME\bin\idea.properties which doesn't help since I can't access that file, but want to change properties in it.
Update: Simple Answer
Create IDEA_PROPERTIES and IDEA_VM_OPTIONS environment variables and point them to the files you want, restart IDE, done.
Also see documentation for more (and maybe report that it lacks any mention of IDEA_PROPERTIES).
You can use %USERPROFILE%\.IntelliJIdea14\idea%BITS%.exe.vmoptions on Windows as custom options file. I tried it and it works.
Another way that I haven't tried, but I think should work, is to copy idea.bat and edit it to use the file you need.

How to share Code Style settings between developers in IntelliJ

I would like all developers on my team to use the same default code style settings. We all use IntelliJ 11+ as our IDE and we use git as our source control system.
What is the easiest way to make sure they're all using the same settings? I thought there would be a way to check in the style settings into the project and have their editors discover them automatically, but that doesn't seem to be the case.
PS. I don't mind if developers consciously override some of the default settings with their own preferences, but I do want to make sure that we all at least start from a common set of default settings.
Code Style can be copied to project and saved in .idea/codeStyles to be shared via version control:
Copy to Project Click this button to create a copy of the current global scheme to the project level. After creating the copy, IntelliJ
IDEA suggests to switch to this new scheme at the project level.
The Settings Repository feature was introduced at IntelliJ IDEA 2016.
This option helps us to share IDE settings between different computers, including sharing settings between developers.
The settings are stored at Git repository, for example on GitHub or Bitbucket.
To setup Git repository we should set URL via Settings Repository menu option.
The developer can load remote settings, overwrite remote settings or merge local settings with remote ones.
The structure of Git repository with settings:
I used personal access token for GitHub authentication.
More information:
Settings Repository
Creating a personal access token for the command line
I came across this long after the fact, but thought I'd share if anyone ran into this. Add the following to your .gitignore
# IDE - IntelliJ
/.idea/*
# Keep the code styles.
!/.idea/codeStyles
/.idea/codeStyles/*
!/.idea/codeStyles/Project.xml
!/.idea/codeStyles/codeStyleConfig.xml
# Keep the inspection levels
!/.idea/inspectionProfiles
/.idea/inspectionProfiles/*
!/.idea/inspectionProfiles/Project_Default.xml
And of course, make sure your .gitignore also has a ! in front of it so these changes get picked up.
Basically, gitignore's recursive looking is a little wonky, so the below ignores a directory's contents, except for a subdirectory, then ignores that subdirectory's contents, except for the files we want.
codeStyleConfig lets you use per project settings, the project file itself is your actual code styles, and I included the Project_Default as it holds the warning levels, which you likely want if you're doing the code style work anyways.
You can create .editorconfig file in Your project (and it can be managed on directory level). More info on https://www.jetbrains.com/help/idea/configuring-code-style.html#editorconfig and https://editorconfig.org/
With this approach You can keep all Your code style settings in one file and it's not limited to IJ only.

Start two instances of IntelliJ IDE

Well my question is pretty simple, how do I start two instances of IntelliJ (community edition).
When I have one instance started and I try to start another one, all that happens is that my started instance gets focus.
I'm developing Android applications using IntelliJ.
Any thoughts?
Press Ctrl+Alt+SChoose Appearance & Behavior, then System Settings, check radio button: Open project in new window.
You need to configure each instance to use its own folders for config/plugins/system locations by editing idea.properties file on Windows/Linux and Info.plist on Mac. You can find the details in FAQ.
Note that normally it's not necessary since you can open multiple projects in different IDEA frames within the same instance using File | Open or Open Recent.
CrazyCoder has roughly the right idea. However, setting the config file alone was not sufficient for me to run multiple instances. Here are my steps to get this going (in GNU/Linux, I am sure you can figure out equivalent in other systems):
Create a folder/directory per instance you want to run.
mkdir -p ~/idea/instance-0
Go to the installation directory (e.g. /opt/intellij) and copy the idea.properties (in bin) file over to your instance directory.
cp /opt/intellij/bin/idea.properties ~/idea/instance-0/
Copy 3 more directories: system, plugins, and config. I highly recommend doing this without the running instance
cp -r /opt/intellij/system ~/idea/instance-0/
cp -r /opt/intellij/plugins ~/idea/instance-0/
cp -r /opt/intellij/config ~/idea/instance-0/
mkdir ~/idea/instance-0/log
Open your idea.properties file and update the configurations for your directories:
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE config folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.config.path=${user.home}/config
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE system folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.system.path=${user.home}/system
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to user installed plugins folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.plugins.path=${user.home}/plugins
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE logs folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.log.path=${user.home}/log
Now, you can start IntelliJ with the new setup:
IDEA_PROPERTIES=~/idea/instance-0/idea.properties /opt/intellij/bin/idea
Obviously, you probably want to put the command in a script file for invocation. This seems to work for me.
File->Settings->General and in section "Startup/Shutdown" check "Confirm window to open project in"
With Ultimate 2020.2, go to Appearance & Behavior > System Settings in the settings dialog and select the "Ask" option for "Open project in"
As per the directions from jetbrains you'll need go to the 'General' page of the 'Settings' dialog and chose 'Open project in a new window'. Then proceed to open a project as you normally do. IntelliJ should then startup a completely new instance.
There is an other very quick way of doing it. There is always an EAP version of the IDE and it can run at same time with the current one. For example I am using AppCode 2017.2 and 2017.3 EAP in parallel.
Go go to IntelliJ | Tools | Create Command-line Launcher...
Keep the defaults (which creates a binary named "idea"):
Now, go to your command line.
Cd to your project directory and type: idea .
This will create a .idea directory for IntelliJ configurations for that project, which it will re-use each time to start IntelliJ from that directory.
You can now go to a different project directory and type: idea .
Assuming you left the previous IntellJ IDE open, you will now have two IntellJ IDEs open, one for each project.
Notes:
1) If your project uses environment variables, then I'd recommending opening a separate terminal tab/window for each project and set that project's environment variables before running: idea .
2) Depending on what you're trying to accomplish, you may need to modify your classpath (or settings like Project GOPATH) for each IntelliJ instance.
My answer is not directly related to the question but its a solution for some cases where we think we need 2 Intellij instances.
For my issue I was thinking to launch 2 Intellij instances. But after careful thinking and searching for other options, I found an easy and quick solution and I wanna share with the community
If you are looking to compare files between different branches, and you wanna compare the difference, that can be done with git comparison. You don't need 2 different Intellij instances.
My Case:
In my case, I wanted to copy very specific code from 1 branch to another and I wanted to compare the difference between the code. The restriction was, I can't do git merge or cherry-pick because we didn't want full commit to be part of new branch. Just few necessary lines were required in the new branch.
My Solution:
Select the branch
Open the file where you wanna insert code
Right Click -> Git -> Compare with... (refer to pic)
Select the branch and you will get the difference
Append or Copy the difference
If you have new files or directories, you can create it manually and copy-paste the content
I know this answer doesn't directly relates to what has been asked, but sometimes we miss alternative solutions.
Hope this can be helpful as an alternative solution.
In addition to the above comments from #crazycoder and #magice, Make sure that you are not trying to load Pycharm with the same project two times which happened to me!!!.
For example, in windows10 already loaded with ONLY one project in PyCharm and tried to load another Pycharm instance by clicking on the PyCharm desktop shortcut or from task-bar if added. In this case, Pycharm will not load the second instance.
I have wasted some time here. So, wanted to share with the community as it will help someone out there!!
Cheers,