Intellij IDE not downloading dependencies after pom update - spring

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

Related

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

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.

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

Building maven project with IntelliJ doesn't create JAR

When running the following command in the terminal, I can see in the target directory the JAR file, whereas when building with IntelliJ I only see the compiled classes.
Why?
To get the jar built by IDE you need to configure the jar Artifact to build:
If you want to build your project and execute run actions through Maven, you need to delegate all those actions to Maven with the Delegate IDE build/run actions to maven option located in the Maven settings.
Build a project with Maven #
Click icons general settings svg in the Maven tool window. Alternatively, from the main menu select File | Settings/Preferences | Build, Execution, Deployment |Build Tools | Maven.
Click Maven and from the list, select Runner.
On the Runner page, select Delegate IDE build/run actions to maven.
more detail see here

IntelliJ IDEA, the Libraries added to the Intellij are not automatically updating pom.xml

In intelliJ IDEA,
I add libraries dependencies in
pom.xml
and "Project Structure -> Project Settings -> libraries -> add ->from maven"
but now, how to write the '2' dependencies to pom.xml automatically?
because there aren't '2' libraries dependency in pom.xml. they aren't synchronization.
I already set Settings > Maven > Importing > Import maven project automatically, Don't work.
note: I want to the Libraries added in the Intellij which can automatically updating pom.xml file.
In settings / Maven, you can switch to "import maven project automatically".
Then, when you modify a pom.xml, it will update your project (ie download new dependencies) automatically
I dont think pom.xml is something which will automatically generate dependencies, If so there wont be any point to maven build type itslef.

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