1

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).

viniciusjssouza
  • 1,235
  • 14
  • 28
  • When you say you removed the dependency, did you do so by editing the pom.xml file or by using the right-click => remove projects dialogue? see: http://stackoverflow.com/questions/19568134/how-to-remove-modules-from-a-intellij-maven-project-permanently – 333kenshin Nov 10 '14 at 14:57
  • I mean by editing the pom. Actually, I did not know any other way of doing it. Editing the pom seems to be the more natural. – viniciusjssouza Nov 10 '14 at 15:41
  • comment from @mugbya: *It may be other external dependencies. Exclude logback is dependent on the situation other default* – GameDroids Nov 10 '14 at 15:55
  • This is not the case. None of the other libraries depends on logback. – viniciusjssouza Nov 10 '14 at 15:59
  • Are you sure that the library is not added by maven? Try using ```mvn dependency:tree -Dverbose``` – Meo Nov 10 '14 at 16:11
  • I tried the dependency:tree goal and had the proof that none of the libraries depends on logback. Still, to prove the issue, I added some other library, it was added to the exploded war and, then, I removed from the pom. The result was the same. The library was still in the artifact. – viniciusjssouza Nov 10 '14 at 16:48

1 Answers1

5

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.

Javaru
  • 30,412
  • 11
  • 93
  • 70
  • The maven helper plugin is great! It showed me the way. We had a strange dependency on spring-boot which depends on logback. I removed it and executed reimport. Now the library was gone. Certainly, it was reported by mvn dependency:tree, but the result was so huge that I couldn't find logback. Now I redirected the output to a file and I managed to find it. Sorry guys, my mistake. Thanks! – viniciusjssouza Nov 11 '14 at 17:56