Skip to content
Advertisement

Cannot resolve symbol, but the dependency is in local repo

I’ve been reading all similar problems with maven but I cannot seem to be able to fix it. The issue is the classic “Cannot resolve symbol ‘pippo'”, in which case pippo is part of

import com.pippo.device.manager.data.model.Device;

This class Device comes from this artifact that I have in my local repo

JavaScript

Evidence that it is in the local repository

JavaScript

and evidence that this is the correct local repository

JavaScript

Just to give you a little bit of context: I’m working on a lab exercise and I created 2 microservices: com.pluto.user.manager and com.pippo.device.manager. They both expose CRUD REST API to work respectively on User and Device. Part of my exercise is to refer to the entity Device from another service (in this case from com.pluto.user.manager) so, in the user.manager, I created an API that is supposed to link the device to the user (it’s just adding an id to the user, nothing serious). And the compiler complains. I even tried to create a docker container with jdk, maven and git, and tried to compile there: same problem.

The class where the error appears is the following

JavaScript

Please, can you help me understand what am I doing wrong?

Edit 1: adding pom.xml of user.manager as requested

JavaScript

and the output of “mvn clean package”

JavaScript

and output of jar -tvf /mnt/c/Users/sanvegeta/.m2/repository/com/pippo/device.manager/0.0.1-SNAPSHOT/device.manager-0.0.1-SNAPSHOT.jar

JavaScript

Edit 2 (closer to the resolution) As Stephen suggested, the internal structure of the generated jar file seems wrong. I crafted an alternative jar file with the paths that don’t start with BOOT-INF/classes, and the user.manager service compiles and runs just fine. Now the question is: how do I instruct spring boot to either generate the correct structure or to “see” the classes?

Advertisement

Answer

I think you have the wrong dependency. By my reading of the jar -tf output, that looks like a SpringBoot executable JAR file. The Device.class file is there, but its path is not right … for a normal Java compiler to resolve it:

This:

JavaScript

needs to be this:

JavaScript

I can’t find any trace of “com.pippo.*” using Google, so I am guessing that this is a private project.

But if you want use the com.pippo.device.manager classes in other modules, you need to modify its POM file to generate a regular JAR, and use that as the dependency.

One suggestion would be to refactor the existing com.pippo / device.manager project into a SpringBoot project and a (new) regular “library” JAR project, with the former depending on the latter. Put the classes that you want to reuse in com.pluto / project.manager into the “library” project.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement