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

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.

Related

How to add a Dependency via Maven for an Eclipse Plug-In Project

I'm working on a Xtext/Xtend based plugin for Eclipse. My project structure contains of various Plug-In projects. The project was created as a maven project and converted to an Xtend project. Developing and building works fine but now I'm at a point where I want to add a dependency (org.apache.poi) to one of the plug-in projects.
I added the <dependency> node from maven central to my pom.xml in the parent project and it got downloaded to my local maven repo. So far so good but when I try to import org.apache.poi.xssf.usermodel.XSSFWorkbook in one of the (child) plug-in projects it can't be resolved.
When using maven in a plain Xtend project I have no problems using it. After adding the <dependency> to my pom.xml I'm able to use it afterwards. So I guess the problem lies in the fact, that I'm now dealing with a plug-in project. At the plain Xtend project, for example, I have a "Maven Dependencies" classpath container which I don't have in my plug-in project.
What I've tried so far:
added the <dependency> to the pom.xml in my parent and/or the child plug-in project where I want to use it
added the dependency via Eclipse GUI (opened pom.xml -> Add Dependency)
added the dependency via right MB on plug-in project -> maven -> Add Dependency
Maven Update Project
clean install -U after adding the dependency
clean/build project
In the MANIFEST.MF I can't add the dependency as it is not shown in the list of dependencies to choose.
What's the way of adding maven dependencies to a plug-in project in Eclipse?

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

How to force intelliJ to import a maven dependency with classifier as a "Maven Library" instead of "Intellij Module"

In my maven based IntelliJ project I have 2 modules - modules A and B.
The pom.xml of module A creates an uber jar (including dependencies which are not accessible by the project) and attaches it as an artifact with classifier "withdeps"
The pom.xml of module B has a dependency on the classified "withdeps" artifact A
When I import the maven modules IntelliJ adds the module's A source code in the dependencies of module B (ignoring the "withdeps" classifier).
Is it possible to force Intellij to add the module A dependency to B as "maven library" instead of the default "project source code/Intellij module"? If not what can I do to resolve the compilation errors in IntelliJ (Ctrl+F9)
Thanks
Open the pom.xml of module B only when creating the intellij project. Then all dependencies will be as maven dependencies.
The downside is that this way you will have to open module A as separate project in another window, then when you change something you will have to do mvn install and refresh project B.
Much better solution would be to install all depencencies into maven repository, described here in maven docs.

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.

Maven beginner question, get m2eclipse to download jar and add to build path?

From what I have read, after adding the relevant maven repositories, maven should automatically download the necessary jars to satisfy dependencies in the pom.xml file.
However, no jars ever get downloaded for me after I add dependencies in eclipse. Am I missing some glaringly obvious step?
I'd recommend to start from creating your project with m2eclipse. See more details in this article.
Basically, you need to make sure the following:
your Eclipse project has a valid pom.xml and all dependencies are available (you should see errors on Maven console, in the Problems or Markers view or when opening pom.xml in m2eclipse's POM editor)
Maven support is enabled for this project (you can use Maven / Enable Dependency Management from popup menu on that project)
project configuration is in sync with pom.xml (you can use Maven / Update Project Configuration from the project popup menu)
you can also use Maven / Update Dependencies to refresh your dependencies (e.g. when you got them in your Local Maven repo from the command line)
Dependencies jars aren't in your project but in your local maven repository.
These jars will be automatically used when you compile you project with maven (or m2eclipse).
If you don't have the needed jar yet, maven will download it for you.

Resources