When IntelliJ starts up I always have te reimport my Maven dependencies - intellij-idea

When I start up my IntelliJ IDEA, all my classes and feature files are not being recognized.
When I reimport all my maven dependencies, it is just working fine, but I have to do this every time I start IntelliJ up.
Is this a setting issue or does anyone has any idea?

It looks like your folders are missing marked "Sources Root", "Test Sources Root" and "Test Resources" -> you can right click on src/main/java, src/test/java and src/test/resources and choose "Mark Directory As..." to do this.
When you first created the intellij project, if you created it off the pom.xml then these folder designations should be in place (since you are following the default). But in your screenshot they arent, so something is amiss here.
Try to add them manually, and see how you go.

Related

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.

What causes JAR files to appear empty to IntelliJ IDEA?

IntelliJ occasionally thinks a gradle managed JAR file dependency is empty. No combination of replacing the JAR on disk, synchronizing, restarting, or clearing IntelliJ caches resolves the issue, so I believe it doesn't like something about the JAR file itself.
In the project tree:
As you would expect, imports from the JAR's packages fail.
Yet, the JAR files are not empty, and compilations outside of the IntelliJ tool chain work fine.
Does IntelliJ have some strict requirement about JAR contents, formatting, or encoding which may be causing this?
There should not be any issue with your jar file and it must be because you have not imported the jar file into the project, you just have copied it inside.
So just right click on it and press "add as library"
Steps for adding external jars in IntelliJ IDEA:
Click File from File menu
Project Structure (CTRL + SHIFT + ALT + S on Windows/Linux
Select Modules at the left panel
Dependencies tab
'+' → JARs or directories
By this way, the 'jar' file will be indexed and also become expandable.
See Correct way to add external jars.
Try exit and reload IntelliJ to trigger indexing, if other solutions don't work.

Java sources replaced by decompiled files in Intellij

When I'm opening a specific class using ctrl + right click I should be redirected to a window with the java sources which contains all the lines and the appropriate comments. But instead I get a window with the decompiled .class file.
I have tried to deactivate the decompiler plugin but it does not work.
If I add http://docs.oracle.com/javase/8/docs/api to Project Structure -> SDKs -> Documentation Paths I can get an overview of the class or method's I'm rolling over, but still can't open the right source file.
Any ideas?
When navigting to sources, IDEA will first go to attached sources. If not present, it will decompile the class and display it.
Try the following troubleshooting to track down the issue:
1. Make sure the sources are properly attached.
For libraries, Open the Project Structure dialog (Ctrl+Alt+Shift+S or ⌘;) and sel4ct "Libraries" on the left under "Project Settings". Find the library in question, and select it. It will show if the source is attached. You mentioned you have Maven's "Automatically download" sources/documentation both checked. So for any maven libraries that have source available, it should be listed.
If it is not listed or is in red, run "Download Sources" or "Download Sources and Documentation" from the Maven tool window. If the source is till in red, it likely means it is not available for that artifact in the maven repository. Use Maven Search to verify such.
For the JDK, select "SDKs" in the Project Structure dialog, find the JDK, and then select the "Sourcepath" tab. Make sure the {jdk-home}/src.zip file is listed.
IDEA should automatically set this when you add the JDK, but if not, add it.
2. Make sure the source JAR/ZIP file is not corrupt
Navigate to the archive in explorer/finder and make sure it can be opened and viewed.
3. Refresh IDEA's Caches
It's possible that IDEA's caches/indexes are corrupted. As such, IDEA is not "seeing" the link between the class and the source code. Go to File > Invalidate Caches / Restart...". Invalidate the caches and restart IDEA. Wait for IDEA to finish re-indexing the project and libraries (watch the progress in the bottom right of the IDEA window).
One of the above should resolve the issue.
FYI, If you do not want IDEA to decompile code(as a backup to no source being present), to the best of my knowledge (and based on the its help page), the only way to do such is to disable the "Java Bytecode Decompiler" in the Plugins list.
After ensuring my sources were attached, checking the source ZIP, invalidating the IntelliJ cache and restarting, I was still having the same problem.
To fix it, I created the project anew File > New > Project From Existing Sources..., and when I got to the library selection step I deselected the .jars for my own modules.

What is root-build in intellij?

Whenever I create an sbt project in intellij, I get something like this:
What is root-build here, and why is it labeled as "sources root"?
When you create an sbt project in IntelliJ, the default root of sbt, called root, is added as a module. You can see this by right-clicking on the project and clicking Open Module Settings. That is what root-build refers to.
You can read a description of content roots on the IDEA site.
I'm just guessing (at least I am being honest) but I believe SBT configuration itself can be considered a "development project" and so is setup as a separate module called "project" for its build, i.e. the build of the build configuration. Notice it has its own "target" directory.

intelliJ 12 - cannot find the xml file i want it to

I want to get, when i press the little green "run me" button in intelliJ, the running program to pick up and use this file (in the project structure)
/src/config/some_folder/some_xml.xml
However, when i press that green run button, intelliJ 12 is giving me this error:
Resource not found on classpath using context ClassLoader: some_folder/some_xml.xml
In an attempt to resolve, this, I have this in my Settings:Compiler: Resource patterns
!?*.java;!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.cl;?*.xml;?*.config
note the penultimate xml entry.
I also unchecked the "use external build" button. I do not know what it means or does, but I read somewhere that it should not be used.
I also have these (among other entries) in Project Structure:Modules: Sources tab
config
config\some_folder
Marked in blue (sources) under the Source Folders heading.
There is no fancy pom.xml for this project - it is an old legacy project. If i add a pom.xml to resolve this, where would i put it, what would i put in it (in entirety) and would i need to tell intelliJ i now have a pom.xml?
EDIT ok, so intelliJ can find the file when i refer to it as
./config/some_folder/some_xml.xml
but will not find it if it is reffered to as
some_folder/some_xml.xml
I think this is the real issue - how do i resolve this?
src/config needs to be configured in the project as a resources folder. In the project tray, right click /src/config and select "Mark Directory As" -> "Source Root"