简体   繁体   中英

Maven picking up dependency of new version

I have a Pom where I have included a dependency for selenium HTML Unit driver. It has a dependency with HtmlUnit v2.18. But While viewing the dependency tree, I was able to see that its picking up another version which I didn't specify, causing issues.

Dependency in my pom:

<dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-htmlunit-driver</artifactId>
      <version>2.52.0</version>
</dependency>

Dependency Tree (from terminal):

org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.52.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-support:jar:2.53.1:compile (version managed from 2.52.0)
[INFO] |  |  \- org.seleniumhq.selenium:selenium-remote-driver:jar:2.53.1:compile
[INFO] |  +- net.sourceforge.htmlunit:htmlunit:jar:2.21:compile (version managed from 2.18)
[INFO] |  |  +- xalan:xalan:jar:2.7.2:compile
[INFO] |  |  |  \- xalan:serializer:jar:2.7.2:compile

You can clearly see that htmlunit:jar:2.21:compile (version managed from 2.18). I was expecting 2.18.

  • I didn't override anything in my pom.xml.
  • Also checked the dependency convergence. There was no convergence for htmlunit:jar

How to resolve this issue without adding the appropriate version in our project pom. Note: In spite of this issue, while building and running the project from console it works fine. But for debugging purpose, I need it to run in IDE like Intellij / Eclipse

This is also one of the cause for the issue - htmlunit driver gives me com.gargoylesoftware.htmlunit.html.HtmlPage cannot be cast to com.gargoylesoftware.htmlunit.InteractivePage error

Please add the mave-enforcer-plugin to find out from which dependency your different version will come:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>3.0.0-M2</version>
    <executions>
      <execution>
        <id>enforce</id>
        <configuration>
          <rules>
            <dependencyConvergence/>
          </rules>
        </configuration>
        <goals>
          <goal>enforce</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

When you know, you could add an exclusion to the dependencies like in this example:

<dependency>
  <groupId>displaytag</groupId>
  <artifactId>displaytag</artifactId>
  <version>1.2</version>
  <exclusions>
    <exclusion>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
    </exclusion>
  </exclusions>
</dependency

Welcome in the jar hell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM