IntelliJ IDEA: How to synchronize project libraries with dependencies in pom.xml?

前端 未结 2 805
时光取名叫无心
时光取名叫无心 2021-01-18 17:13

When I change a dependency version in one of the pom.xml of my project (which has several modules) I see the new version and also the old one in the Libraries section of the

相关标签:
2条回答
  • 2021-01-18 17:55

    Well, this is not problem with synchronize project libraries.

    The synchronization settings can be set via Settings > Maven > Importing > Import maven project automatically

    But I think this is other problem. It is caused by other dependency which uses different Drools version. You have to exclude the old Drools version from that dependency explicitly.

    How to find this problem causing dependency?

    Open your dependency tree. It can be done via right click on your maven module and click Show dependencies or hit Ctrl + Alt + Shift + U.

    There will be some red lines leading to different version of the same maven artifact. Just click on it and Idea will lead you where the inconsistency happened. Then just right click on maven artifact with wrong version and click Exlude or Shift + delete.

    Check your pom.xml. You should find line like this:

    <exclusions>
       <exclusion>
          <artifactId>drools</artifactId>
          <groupId>drools</groupId>
          <version>5.4</version>
        </exclusion>
    </exclusions>
    
    0 讨论(0)
  • 2021-01-18 17:59

    Thank you very much, Milan.

    The problem in my case seems to be an IntelliJ bug (or feature!) but your answer has been really helpful so I will mark it as accepted. It seems that IntelliJ doesn't update dependency versions for grandchildren.

    I'll explain what happens.

    I have a parent POM (P) and two children POMs (C1 and C2).

    The parent P defines some properties including:

    <drools.version>5.4.0.Final</drools.version>
    

    Child C1 depends on that Drools version using:

    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>drools-core</artifactId>
      <version>${drools.version}</version>
    </dependency>
    

    C2 depends on C1 so it depends on that Drools version indirectly.

    If I change the version in the parent POM to 5.5.0.Final and import changes (of that POM) then the Libraries section of the Project Structure window includes both versions: 5.4.0.Final and 5.5.0.Final.

    The reason is C2 still thinks it depends on the old version. The dependency tree for C1 shows the right version 5.5.0.Final of Drools. However, the dependency tree of C2 shows a dependency on C1 (right) which in turn depends on the old 5.4.0.Final version (wrong).

    To fix that, I reimport C1's POM (or all POM's I guess). Then the 5.4.0.Final is gone from the Libraries and the dependency tree of C2 reflects the right Drools version.

    0 讨论(0)
提交回复
热议问题