Why do I constantly have to add a library to the classpath?

Answered

I've been working on a Maven project for a while now.

In my parent POM, I have the following:

            <dependency>
                <groupId>net.project.class</groupId>
                <artifactId>java-test-utils</artifactId>
                <version>1.0.8-SNAPSHOT</version>
                <type>bundle</type>
            </dependency>

In my POM, I have the following:

        <dependency>
            <groupId>net.project.class</groupId>
            <artifactId>java-test-utils</artifactId>
            <type>bundle</type>
            <scope>test</scope>
        </dependency>

Maven resolves this just fine, but every so often (seems like when IDEA is "resolving dependencies"), I'll start getting errors in my Java classes. In this particular case, it's under project/src/test/java/...

The only way to fix the issue in IDEA is to do Alt+Enter (I'm on Mac), and choose "Add library 'Maven: net.project.class:java-test-utils:bundle:1.0.8-SNAPSHOT' to classpath"

And then when I'm resolving dependencies again, I have to add it to the classpath again! Is there a solution to this? Is this a bug?

There are other times where instead of adding something to the classpath, I have to "Add dependency on module 'other-module'".

This is occurring since IDEA X and is present in 10.0.1, 10.0.2, 10.0.3, and 10.5.

5
31 comments

@Alvarohispania thank you! Imported a fresh branch of a legacy maven project and was experiencing the same issue which was driving me crazy. Checked the module settings after seeing your post and like you apart from the application there were an additional two modules which had been created for test and main. Removed both of them and all the classpath errors have gone. Legacy project has thousands of classes so this was causing serious delays upgrading library dependencies.

0

Please sign in to leave a comment.