dtech
dtech

Reputation: 14060

IntelliJ not loading transitive dependency in maven project

I've made a small library, lets call it lib. It dependends on another library, sublib which is available in Maven central:

lib/pom.xml:

<dependencies>
    <dependency>
        <groupId>3rdparty</groupId>
        <artifactId>sublib</artifactId>
        <version>x</version>
    </dependency>
</dependencies>

Now I'm trying to use lib in my project proj. I've set it as a dependency:

proj/pom.xml:

<dependencies>
    <dependency>
        <groupId>mynamespace</groupId>
        <artifactId>lib</artifactId>
        <version>y</version>
    </dependency>
</dependencies>

When I run mvn exec:java -D exec.mainClass=mynamespace.proj.Main the program runs fine. However if I run it from IntelliJ, I get the following error:

java.lang.NoClassDefFoundError: 3rdparty/SomeSubLibClass
    at mynamespace.SomeLibClass.method(SomeLibClass.java:100)

This seems to indicate that IntelliJ does not load the transitive sublib dependency. How can I fix this?

Upvotes: 7

Views: 3254

Answers (3)

pushpavanthar
pushpavanthar

Reputation: 869

I had a similar problem. The below command resolved the problem. It downloaded all the dependency jars into my IDEA project.

mvn -U idea:idea

Upvotes: 1

Dave
Dave

Reputation: 1

What worked for me was changing from using maven (Intellij) version and using my latest version that was installed on my machine previously.

Upvotes: 0

kuporific
kuporific

Reputation: 10322

You can manually right click on the pom.xml file in the file tree and select maven > reimport.

Sometimes you'll see a popup saying "Maven projects need to be imported"; you should select Enable Auto-Import.

Maven auto import popup

This option can be found in Preferences > Maven > Importing > [x] Import Maven projects automatically (and is unchecked by default):

enter image description here

Upvotes: 7

Related Questions