Search code examples
javamavenhtmlunit

mvn dependency causing NoSuchMethod errors with htmlunit


I have dependency:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.10</version>
</dependency>

And run a test that includes testing a website for form submission. Works great. I package this up into my local repo mvn install and include it in another wider project.

Doing a mvn dependency:tree -Dverbose -Dincludes=net.sourceforge.htmlunit doesn't seem to reveal anything untoward

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ myproject ---
[INFO] com.myproject:myproject:war:1.0-SNAPSHOT
[INFO] \- com.myproject:myproject:mp:jar:1.0:compile
[INFO]    \- net.sourceforge.htmlunit:htmlunit:jar:2.10:compile
[INFO]       \- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.10:compile

So I don't think any of the other deps are causing an issue. Yet if I copy/paste a test from the base project into the wider one, I always get errors:

java.lang.NoSuchMethodError: com.gargoylesoftware.htmlunit.html.HtmlPage.getElementById(Ljava/lang/String;)Lcom/gargoylesoftware/htmlunit/html/HtmlElement;

I've made sure my IDE isn't caching some dodgy library somewhere so as far as I can tell it's clean. Any ideas?

Thanks


Solution

  • Problem is you have this class coming from some other artifact, since you verified it is not directly coming from htmlunit with different version, it must be shaded in some other jar

    for jvm to get pick up correct class please put htmlunit dependency on top of dependency so it will be first in classpath taking priority