Tutorial :In IDEA, after adding a dependency in maven, my artifact always show's the library needs to be 'fixed'



Question:

So every time I add a dependency to a library using maven in my pom.xml, it doesn't get deployed until I go to module settings and then click on 'fix'.

This happened when I added freemarker.

Why doesn't IDEA do this for me? Am I missing a step?


Solution:1

Not sure about previous versions but with IntelliJ 9, IntelliJ shows me a Import Changes link when I modify a pom.xml and also offers to Enable Auto-Import:

alt text http://www.imagebanana.com/img/emcut3ku/screenshot_008.png

The auto-import option is also available from the Maven Integration dialog: File > Settings > Maven > Importing > Import Maven projects automatically.


Solution:2

IDEA stores all of your module's dependencies in either a .iml or .classpath file (based on your preference).

When you change the pom.xml file, it needs to resolve the new set of dependencies (Re-import) and update the file accordingly. I can only imagine that they don't do this automatically for you because they can never really know when you are done working with the file, and causing resolution of dependencies to start while you're still typing would make working with pom.xml from within idea very irritating.

AFAIK, you're doing it right. In my version of IDEA, I see a "re-import" button that appears in the pom file editor (which saves a couple of clicks)... or you can go to the "Maven Projects" window and click the "Re-Import Maven Projects" button, but these should do the same thing as your "Fix" button in the project settings.


Solution:3

The original question referred to a library that wasn't deployed -

IntelliJ uses artifacts to deploy build output and required libraries to application/web servers, and currently those can include a constant list of dependencies. Clicking the "fix" simply adds module dependencies to the artifact, if they weren't already there.

Since in most use-cases this is 1:1, i.e. artifacts contain all module dependencies, I have opened an feature issue for it:

http://youtrack.jetbrains.com/issue/IDEA-99458


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »