Why intelliJ doesn't show maven dependency as External dependencies and also shows red symbols even though the dependencies are downloaded - maven

I'm cloning my maven project from GIT and then doing mvn clean install. My dependencies are downloaded successfully, but I'm not able to see it in External Libraries. Also my code shows red colored as if dependencies are not available. I did Invalidate cache/restart, did re-cloning, removed .idea folder, but no luck.
Any solution to this?
THanks!

Make sure you have opened the Project as Maven project and that it has been imported successfully from Maven pom.xml build file. In an existing project you can import Maven from Maven tool window. See Link a Maven project
steps:
Open the Maven tool window.
In the Maven tool window, click the + icon to attach a Maven project.
In the dialog that opens, select the desired pom.xml file, and click OK.

Related

Intellij IDE not downloading dependencies after pom update

I'm using Intellij IDE for Spring projects. Whenever I add a dependency in pom file, it's not downloading it. In the case of Eclipse IDE, it automatically downloads the dependency whenever a dependency is added in pom.xml file.
I added the highlighted dependencies in the pom.file but it's not downloading. How to configure the IDE for auto-download dependencies whenever the pom.xml is updated?
You can tick the checkbox "Import Maven Projects automatically"
under "settings" -> "Build, Execution, Deployment "
-> "Build Tools" -> "Maven" -> "Import Maven projects automatically"
Usually, if do some modification in pom.xml, the Intellij will give always suggest you to enable Auto Import in a small pop-up(). I think it might have suggested you already. Anyways, you can do the above.
In Eclipse project build automatically it that option is enabled as build automatically
but idea we can not load maven dependency just by adding it in pom.xml but we can build the project by
IntelliJ Idea - Preferences
Select “Build, Execution, Deployment -> Compiler” -- build Project automatically
Above will build the project but it will not download the dependency
We have to click reload all maven project icon under maven tool window which can be activated by view - Tools Windows - maven

No maven in intellij idea

I have one project open in IntelliJ. In that I am able to see maven tab in its left sidebar:
Also, I am able to see Maven in View > Tool Windows > Maven:
I tried to open another project in another IntelliJ window, but it does not have both of the above:
It may be not required to have that maven tool window for the project that you have opened in the second Idea instance.
If the opened project is a maven project (at least if you have a pom.xml associated with that project) you will have this option available in View -> Tool Windows -> maven
If it's a maven project, try importing the project as a maven project as well

missing artifact org.elasticsearch:elasticsearch:jar:5.0.0-alpha1

Even though I can see the JAR file in Maven Dependencies and in .m2/repository directory, I still get this error.
missing artifact org.elasticsearch.elasticsearch
Do you have any idea where I am doing wrong?
I have met the same question.You can try the flowing steps:
1.make sure your network is well connected.
2.go to .m2/repository,delete all the files
3.restart your project and run maven install and maven update.
After running a build from the shell (mvn clean install, etc.) and making sure the problem is caused by Eclipse - there are a few options:
First, try Project --> Clean...
Right click on the project in the Project Explorer pane and then choose Maven --> Update Project...
Disable and then re-enable Dependency Management - right click Maven --> Disable Dependency Management and then Maven->Enable Dependency Management
Close the project and then reopen it.

run maven project with eclipse

I'm new to maven and eclipse. I added m2e-plugin in eclipse and I imported an example of a maven project that I've found in the net.
My problem is when I try to run the project in eclipse using the Run as item menu, I don't find the maven package menu as I learned in the different tutorials.
Is it a problem of installation?
Ok, lets go through this step by step to make sure you have everything you need to get going.
First of all make sure that you have Maven installed (and lets assume you have Java already). You can download it from http://maven.apache.org/download.cgi and installation instructions for Fedora (which I assume is what you are using from your tag) are further down the page.
To test that Maven is correctly installed and working type mvn --help in to the terminal. Eclipse and m2e pretty much just hop on to the terminal for everything Maven related so make sure this is working before proceeding.
Next download an appropriate version of Eclipse. For the sake of this example I've downloaded the Kepler version of the Java EE IDE. In this version of Eclipse m2e comes bundled and to check this you can go to Help > About Eclipse > Installation Details and on the plug-ins tab you should see the m2e connectors.
Now you can import your Maven project in to Eclipse. To do this go to File > Import and then choose Existing Maven Projects under the Maven section. Choose the directory with the example project that you've downloaded and then Finish.
Now, ensure that you have some file inside your example Maven project opened and when you go to Run As... you should now be able to see the maven options. Go to Run As > Maven build... and all you need to do is place the word package in the Goals field and you're ready to roll.
Convert your project to a maven project if you haven't done yet by right clicking on your project in the Eclipse Project/Package explorer. Then follow:
Configure -> Convert to Maven Project
After that you can just right click again on the project Run as and you will see all Maven possibilities to execute your project build/install/clean etc.

How can I make IntelliJ IDEA update my dependencies from Maven?

When I manually add dependencies in the pom.xml of my project, let Maven download the dependencies and let IntelliJ build the module, IntelliJ complains about missing libraries. At the same time Maven can find the dependent JARs and build the project.
How can I tell IntelliJ to use the libs which are downloaded by Maven?
It turns out IntelliJ does not pick up added dependencies from the local Maven repository. We have to tell IntelliJ to reimport the pom.xml.
Open the project view in IntelliJ
Right click the pom.xml file and select Maven > Reimport or Maven > Reload (for newer versions of IntelliJ)
If this works for you IntelliJ will add the dependencies to the project
Check the if the dependencies you need are added in
File - Project Structure - Project Settings - Libraries
and File - Project Structure - Modules - Dependencies
You don't have to reimport manually each time. You can enable auto-import as documented here. Change this in Settings -> Maven -> Import Maven projects automatically.
IntelliJ IDEA 2016
Import Maven projects automatically
Approach 1
File > Settings... > Build, Execution, Deployment > Build Tools > Maven > Importing > check Import Maven projects automatically
Approach 2
press Ctrl + Shift + A > type "Import Maven" > choose "Import Maven projects automatically" and press Enter > check Import Maven projects automatically
Reimport
Approach 1
In Project view, right click on your project folder > Maven > Reimport
Approach 2
View > Tools Windows > Maven Projects:
right click on your project > Reimport
or
click on the "Reimport All Maven Projects" icon:
You need to go to: Maven settings -> Auto-Reload Settings
Then check "Any Changes":
File>Settings>Build,Execution,Deployment>Maven>
Check : Always update snapshot
That worked for me.
Uncheck
"Work Offline"
in Settings -> Maven !
It worked for me ! :D
For some reason IntelliJ (at least in version 2019.1.2) ignores dependencies in local .m2 directory. None of above solutions worked for me. The only thing finally forced IntelliJ to discover local dependencies was:
Close project
Open project clicking on pom.xml (not on a project directory)
Click Open as Project
Click Delete Existing Project and Import
in IntelliJ 2020 in the pom.xml view one should be able to apply pom changes by following key combination: CTRG + SHIFT + O.
And as correctly commented before - IntelliJ additionally shows a balloon widget to import changes.
I tried absolutely everything to get IntelliJ to pickup my pom.xml changes but it just wasn't doing it. I commented out all of the <dependencies> in pom.xml and rebuilt the project which should've shown hundreds of compile errors but didn't.
In the end, I had to delete the .idea folder to get IntelliJ to regenerate it's maven model. Once I did this, subsequent changes to pom.xml were picked up when I did a "Reload All Projects" so I suspect a bug where IntelliJ is using a cached model rather than updating it when changes are made.
Here's what I did:
Close the project in IntelliJ (file -> close project)
Delete the .idea folder in the root folder of the project
Open the project again in IntelliJ
Maven -> Reload All Projects
Build -> Rebuild Project
Todays, there is a Reload Project option under the Maven tab when you do mouse right-click inside the pom.xml file.
Apart from checking 'Import Maven projects automatically', make sure that settings.xml file from File > Settings > Maven > User Settings file exist, If doesn't exist then override and provide your settings.xml file path.

Resources