viniciusjssouza
viniciusjssouza

Reputation: 1275

Intellij - Trouble with maven dependencies synchronization

I am working with IntelliJ 13.5.1 and I am not understanding the maven synchronization mechanism. We switched our logging mechanism from logback to log4j. When I removed the logback dependencies from my pom, the dependencies were removed from maven but not from the project, even if a I try to reimport the maven module. In other words, IntelliJ synchronizes correctly the addition of new libraries but not the removal.

Is it a bug of this IntelliJ version?

Note: When I remove the dependency from the pom, the jar still appears in the generated artifact (exploded war).

Upvotes: 1

Views: 6453

Answers (1)

Javaru
Javaru

Reputation: 31936

IDEA should remove any dependencies removed from the POM assuming they were initially add via the POM (and only via the POM). If you manually added a dependency, it will stick around. Here are some things you can do to resolve the issue:

1) Run a reimport enter image description here from the maven tool window. Wait for it to finish (watch the progress in the status bar at the bottom right). Then immediately run it a second time. Although I normally don't like answers like this, a couple of time I have seen cases that it takes a double import in a row for IDEA to properly resolve a modified POM.

2) Go into the Project Structure dialog, and select 'Libraries' under the , "Project Settings" label on the left. (not 'Global Libraries, but just 'Libraries') Look for the unwanted dependencies. In line search should work. (Note: if the dependency does not start with "Maven:", then it was not added by maven). Select it and remove it. Once they are all gone, close out and reimport the maven project. See if they return. If so, they are getting pulled in from some where.

3) You mentioned you ran a dependency tree, so that would seem to indicate maven is not pulling in the dependency. To double check this and be absolutely sure, I recommend you use the Maven Helper plugin. Install it from the Plugin settings dialog and restart IDEA. After restarting, go to your pom file. At the bottom you will now have a 'Dependency Analyzer' tab. Select it. Then select "All Dependencies" at the top. Search for logback. If is is found, select it, and on the right you will see an inverse tree of how it is pulled in. For example, for hamcrest, I see the following, telling me junit is pulling it in.:

enter image description here

Do this for all your pom files.

Upvotes: 5

Related Questions