How to enable autoscroll to/from source permanently for all new project imports? - intellij-idea

I like the "Autoscroll to/from source" features. Every time I import a new project, I will always enable them. However, it gets annoying when you have to do that every time for a new import. I googled, but couldn't find out how. How can I enable them permanently?

There is now a free IntelliJ plugin to remember Autoscroll to/from Source settings:
Jetbrains repository: Autoscroll Save Plugin
Instructions to use:
Download Autoscroll Save plugin and restart IntelliJ
Open an IntelliJ project and set desired autoscroll to and from settings
Use Ctrl-Alt-Shift END
All IntelliJ projects opened or created in future will now inherit your desired Autoscroll to/from Source settings.
If you have any feedback on the plugin, please click on the author (vikingsteve) on the plugin page and use "Send email" function.
Edit: I was just at a java conference and spoke to some of the Jetbrains devs from St Petersbourg. After thanking them for developing IntelliJ, I asked them about this, and I understand that since they are really busy with other things they don't have time right now to make this default functionality in IntelliJ.
So, in the meantime, please try out the Autoscroll Save plugin - from everyone I spoke to at the conference, it works for them without problem.

This is currently not possible.
The auto-scroll settings are Project specific and are stored in the .idea/workspace.xml file :
Accessing Default Project Settings and Structure documents how to change the default settings used by new projects. Unfortunately, the autoscroll settings are not amongst the ones that can be set there.
A bit more digging shows that the default project is represented by .IntelliJIdea12\config\options\project.default.xml and it does not have settings for autoScroll specified. (Out of curiosity, I tried copying in the following in that file :
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1" splitterProportion="0.5">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource ProjectPane="true" />
<autoscrollFromSource ProjectPane="true" />
<sortByType />
</navigator>
</component>
But that was not picked up by new projects.
)

Related

Intellij codeStyleSettings.xml vs codeStyleConfig.xml vs codeStyle.xml

I want to set code style for the project so that all the developers of the project format the code the same way. All of the team uses IntelliJ. When I add my style in the file
/myproject/.idea/codeStyleSettings.xml
the IDE creates the file
/myproject/.idea/codeStyles/codeStyleConfig.xml
with the contents
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
Will the default settings override my code style settings? Should I use the same component name in my settings file to override the default one?
In addition to those, I see a codeStyle.xml file in the root directory of some well-known java libraries such as https://github.com/qos-ch/slf4j , is it for another IDE or does that also have an impact on formatting in IntelliJ?
By the way, I think generally code style config is confusing if not mess, there is also IDE level global settings and I think/hope it will be applied when there are no rules for a specific option, right?
Intellij IDEA 2017.3 has got new project code style settings format. Now all code style settings are located under <PROJECT_ROOT>/.idea/codeStyles directory with the ultimate intention to support multiple project code styles linked to different scopes. New code style settings format is also cleaner and contains all code style settings properly grouped per language. Some old legacy Java, HTML settings previously stored without any language tag are moved to "JavaCodeStyleSettings", "HTMLCodeStyleSettings" etc. respectively.
The old .idea/codeStyleSettings.xml is imported into two new files: .idea/codeStyles/codeStyleConfig.xml containing a link to preferred project code style and .idea/codeStyles/Project.xml with code style settings for different languages. The latter is optional and created only if there are non-default settings. If .idea directory is under version control, both files can be added to VCS too. The old codeStyleSettings.xml is kept for backwards compatibility.
Original answer (now obsolete):
.idea/codeStyleSettings.xml stores the project specific code style that is for sharing with the project so that all the team members have the same code style applied automatically for this specific project. Check this answer for details.
.idea/codeStyles/codeStyleConfig.xml is used to override the default project code style.
By default it contains <option name="USE_PER_PROJECT_SETTINGS" value="true" /> so that project specific configuration from .idea/codeStyleSettings.xml is used. If you switch your code style settings to use a scheme stored in the IDE instead of the project scheme, this file will store your choice.
IntelliJ IDEA also has support for .editorconfig which will have the priority and override IDE and project scheme by default. Check the documentation for more details.
codeStyle.xml in the project root is for Eclipse IDE and is not used by IntelliJ IDEA. It can be probably used by IntelliJ IDEA as well, if you have Eclipse Code Formatter plug-in installed and configured accordingly.

Intellij is not showing "External Libraries" in Project Tab

There is nothing on left. It is a maven project. Why?
I've had the same problem and narrowed it down to the following configuration that might have been messed up during the upgrade.
File (on Mac): ~/Library/Preferences/IntelliJIdea2018.1/options/projectView.xml
<application>
<component name="ProjectViewSharedSettings">
<option name="showLibraryContents" value="false" />
<option name="showMembers" value="true" />
</component>
</application>
Change/remove the showLibraryContents entry. This setting is no longer available in the UI, "External Libraries" are always shown.
I solved this by selecting "Project" as view (by default i had "Project Files"). Hope this helped.
Project View VS. Project Files view
I was facing the same issue on windows, i solved it by
right click on pom.xml > maven > reimport
Then reopen the project, It worked for me.
Hmmm, it seems I have seen this same kind of thing recently. Check your module settings (right click on highest level folder - open module settings, or Command-;). Make sure you have one module if it is a single-POM project, and check the sources, paths, dependencies tabs and make sure they look right. I think I've seen this once when I created a module manually rather than letting intellij create one for the Maven module automatically.
That "recycle/refresh" icon on the far right pane you show - the Maven project pane - can also sometimes get it to fix things it didn't get right when you initially check out project.
If maven re-import does nothing, check your pom.xml for errors and try commenting out the offending ones (marked in red).
In Intellij: Ctrl + Alt + Shift + S -> Select Modules and ensure that there is only one module. Delete the other ones.
If all else fails:
In Intellij, Select "Invalidate caches/Restart" -> Close Intellij -> Go to the project folder and delete .idea folder -> Reopen Intellij and "mvn clean install"
Deleting ./idea directory and re-importing the project worked for it.

JavaFX - (IntelliJ) FXML loader (NullPointerException: Location is required)

I get a NullPointerException for FXML loader when I execute the below in IntelliJ, but not in Eclipse IDE
Parent root = FXMLLoader.load(getClass().getResource("/view/MainView.fxml"));
Please note, the project is the same (not copy) opened in the 2 IDE's simultaneously, since it is the same project opened, the file / folder structure is the same. My search in this forum & on google for this specific issue so far has drawn blanks.
Seek guidance as to what settings I need to check / change in the IntelliJ to get it working?
Managed to resolve this finally.
I re-imported the project to IntelliJ as a Gradle project & added the steps in Gradle Build file as mentioned in the link earlier.
The same error occured to me. My project used to be a Maven project, but I tried to remove all of those components. It appears I didn't quite succeed in doing so.
I noticed that the fxml files were not properly copied into the target directory.
In .idea/compiler.xml I changed the following line:
<profile name="Maven default annotation processors profile" enabled="true">
to now read:
<profile name="Maven default annotation processors profile" enabled="false">
This fixed the problem and allowed the FXMLLoader to find the fxml file.

popup:org.eclipse.jdt.ui.PackageExplorer not visible for Java projects

I'm writing a plugin for Eclipse to help me with some custom errors and warnings. Started by creating a new plugin project using the wizard, chose the option with the nature and markers in it.
This automatically added a menu item in the project's context menu (popup:org.eclipse.jdt.ui.PackageExplorer?after=additions)
This seemed to work for most projects. Except the projects i needed it for. The menu item simply does not show up for Java projects in the Package Explorer.
I only changed the default ?after to be ?before, so the menu-item is in a location that suited me better (for the projects that it does work on).
Screenshot if what i've got now
That shows it's working on a non-java project in the Package Explorer.
I also added the same menu-item to the Project Explorer, all works fine there.
Here is a link to the plugin.xml i currently have.
The project it DOES NOT work on, is a simple java project freshly generated from the Eclipse "New -> Java Project" wizard. Any other java project doesn't work either.
The project it DOES work on, is freshly generated from the "Plug-in Development -> Update Site Project" wizard.
Stuff i tried:
I know it is not the same as popup:org.eclipse.jdt.ui.PackageExplorer not visible, i'm adding the menu-item to the context menu of a project, not files or directories.
However, i did try using:
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.contentTypeId" value="org.eclipse.jdt.core.IJavaProject" />
</adapt>
instead of the <instanceof> tags, which also did not work. in fact, removing the whole <instanceof> tag does not even work.
I know it is not the same as Eclipse plugin menu item is not visible, the generated plugin.xml used selection, which i later changed to activeMenuSelection because that matched the documentation, and what the Plug-in Selection Spy says it actually is. Again, no change.
I think it is not the same as How create popup menu item in PackageExplorer only for directories, but i did try to use the suggested code and toyed around with it, no luck.
So, to summarize:
This is my first Eclipse plugin, most of the GUI stuff is generated from the Plug-in Developent wizard. Now i hope a real wizard can lead me to the answers i seek.
The <adapt> tag gave me an idea to adapt the project to an IResource. Then check for natures from inside the <adapt> tag. And that seemed to work!
The Platform Expression Framework page at eclipse.org also helped me understand what each of the tags exactly do.
So, i think my problem was actually similar to the one i linked first (popup:org.eclipse.jdt.ui.PackageExplorer not visible). Feel pretty dumb about that now...
Relevant part of my current plugin.xml:
<visibleWhen checkEnabled="false">
<with variable="activeMenuSelection">
<count value="1" />
<iterate operator="and">
<adapt type="org.eclipse.core.resources.IResource">
<and>
<not>
<test property="org.eclipse.core.resources.projectNature" value="com.mycompany.converterhelper.javaFileNature" />
</not>
<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.jdt.core.javanature" />
</and>
</adapt>
</iterate>
</with>
</visibleWhen>
And a link to the entire plugin.xml
I want to thank Calon for his time and effort :-)

Adding a directory path under IntelliJ 12 claims Library 'LibraryName' is not used and has no effect

I maintain an IntelliJ plugin (Codename one) and we need to control the users classpath. I'm adding a classpath either via the plugin or manually by going to here:
And pressing the + sign where I pick Java:
Then choose classes:
This seems to work OK:
But the completion and other such functionality doesn't work and when I go back the entry is disabled and I get this error message:
This doesn't really tell me anything?
A workaround is to open the .iml file in a text editor, and add the following to the orderEntry list:
<orderEntry type="library" scope="PROVIDED" name="LibraryName" level="project" />
Unfortunately this isn't very practical and it only solves some of the problems I'm experiencing. Any direction or hint would be appreciated here.
Edit: Adding screenshot of preferences UI:
Second Edit: Screenshot of the module section
The answer from kukido is good, for additional details though check out this: http://devnet.jetbrains.com/message/5509300
Essentially what I want is to still have my module but add a dependency programmatically which can be done by:
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
model.addLibraryEntry(library);
model.commit();
This doesn't really tell me anything?
IntelliJ is trying to warn you that you have created a library, but it is not referenced anywhere in the project. It is gently asking "Did you mean to add this library as a dependency?".
The entry is not disabled. It is greyed out to show that it is not referenced in any module as a dependency. Once you add the library to the dependencies list, the color will change.
It is a two-step process:
Create a library
Reference new library in a module
Code completion is not working because your module is not aware of the library classes.
Module dependencies
Non-referenced and referenced libraries