vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

imports are not resolved in maven multi module project

Open ck-c8y opened this issue 2 years ago • 6 comments

Hi,

I use vcode for a multi module project cumulocity-dynamic-mqtt-mapper, (branch develop).

The project structure is as follows: |----mqtt-mapping-service |  |----pom.xml |----mqtt-mapping-interface |  |----pom.xml |----mqtt-mapping-extension |  |----pom.xml |----pom.xml

When ...

  1. I open the project in vcode (extension pack vscjava.vscode-java-pack) and
  2. navigate to the module mqtt-mapping-extension and
  3. open class mqtt-mapping extension/src/main/java/mqtt/mapping/processor/extension/external/ProcessorExtensionCustomEvent.java
  4. I see the following errors: The import mqtt.mapping.model cannot be resolvedJava(268435846) mqtt.mapping in the source editor: Screenshot 2023-07-13 at 23 03 24
Environment
  • Operating System: MacOS
  • JDK version: OpenJDK 64-Bit Server VM Zulu11.60+19-CA (build 11.0.17+8-LTS, mixed mode)- Visual Studio Code version:
  • Java extension version: v0.25.12
Steps To Reproduce
  1. clone the project (https://github.com/SoftwareAG/cumulocity-dynamic-mqtt-mapper/tree/develop)
  2. navigate to the module mqtt-mapping-extensionand open class mqtt-mapping-extension/src/main/java/mqtt/mapping/processor/extension/external/ProcessorExtensionCustomEvent.java
Expected Result

When I open the same project in IntelliJ I don't get any errors. In can use classes from the module mqtt-mapping-interface in the module mqtt-mapping-extension.

Regards Christof

ck-c8y avatar Jul 13 '23 21:07 ck-c8y

@sagIoTPower Could you try the following patch:

diff --git a/mqtt-mapping-extension/pom.xml b/mqtt-mapping-extension/pom.xml
index a5fc808..18800c0 100644
--- a/mqtt-mapping-extension/pom.xml
+++ b/mqtt-mapping-extension/pom.xml
@@ -60,6 +60,11 @@
             <artifactId>mqtt-mapping-interface</artifactId>
             <version>${revision}</version>
         </dependency>
+        <dependency>
+            <groupId>com.softwareag.c8y.mqtt</groupId>
+            <artifactId>mqtt-mapping-service</artifactId>
+            <version>${revision}</version>
+        </dependency>
     </dependencies>
     </dependencyManagement>
 
@@ -69,6 +74,11 @@
             <artifactId>mqtt-mapping-interface</artifactId>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>com.softwareag.c8y.mqtt</groupId>
+            <artifactId>mqtt-mapping-service</artifactId>
+            <scope>compile</scope>
+        </dependency>
         <dependency>
             <groupId>com.google.protobuf</groupId>
             <artifactId>protobuf-java</artifactId>

snjeza avatar Jul 14 '23 00:07 snjeza

@snjeza thank you very much for your proposal. This works indeed.

But I still do not understand why this is additional dependency:

       <dependency>
            <groupId>com.softwareag.c8y.mqtt</groupId>
            <artifactId>mqtt-mapping-service</artifactId>
            <version>${revision}</version>
       </dependency>

is required?

It is only required for the editing in vscode. I don't need this dependency when I run mvn from the command line and I don't need in IntelliJ.

ck-c8y avatar Jul 14 '23 05:07 ck-c8y

@sagIoTPower It is an upstream m2e issue. I can reproduce it in eclipse. You can create a new issue at https://github.com/eclipse-m2e/m2e-core/issues

snjeza avatar Jul 14 '23 17:07 snjeza

i got the same problem. my multi mudules pom file like this image compile error is this :The import com.fajiajia.cloudcommon cannot be resolved, image but when i open this error file, it disappear soon, image and when i rebuild the projects ,the error comes again. can‘t understand it at all. i tried to clean cache storage, restart ,rebuild .... and many other ways. but not work. i don't know how to fix it, someone meet the same problem ,can help me ? thanks.

JACKROMER avatar Jan 16 '24 06:01 JACKROMER

@sagIoTPower Could you provide a project example?

snjeza avatar Jan 16 '24 14:01 snjeza

@snjeza: I created a branch to demonstrate the error. bug-vcode-java In vscode it does not work: error_vscode but the same works in intellij: works_intellij

ck-c8y avatar Jan 17 '24 19:01 ck-c8y

i got the same problem. my multi mudules pom file like this image compile error is this :The import com.fajiajia.cloudcommon cannot be resolved, image but when i open this error file, it disappear soon, image and when i rebuild the projects ,the error comes again. can‘t understand it at all. i tried to clean cache storage, restart ,rebuild .... and many other ways. but not work. i don't know how to fix it, someone meet the same problem ,can help me ? thanks.

facing the same issue here

ifrankwang avatar Mar 16 '24 08:03 ifrankwang

Here's some output logs for the plugin:

 message: StaffDTO cannot be resolved to a type; code: 16777218; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/converter/ApprovalFlowConverter.java; line: 77
 message: The import com.xx.basic cannot be resolved; code: 268435846; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/converter/ApprovalFlowConverter.java; line: 10
 message: No implementation was created for ApprovalFlowConverter due to having a problem in the erroneous element null. Hint: this often means that some other annotation processor was supposed to process the erroneous element. You can also enable MapStruct verbose mode by setting -Amapstruct.verbose=true as a compilation argument.; code: 0; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/converter/ApprovalFlowConverter.java; line: 24
 message: The method getData() is undefined for the type Object; code: 67108964; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 256
 message: The method getData() is undefined for the type Object; code: 67108964; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 258
 message: StaffDTO cannot be resolved; code: 570425394; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 259
 message: The method disjunction(Collection<T>, Collection<T>) in the type CollUtil is not applicable for the arguments (List<Long>, Object); code: 67108979; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 262
 message: The method getData() is undefined for the type Object; code: 67108964; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 267
 message: The import com.xx.basic cannot be resolved; code: 268435846; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 13
 message: The import com.xx.basic cannot be resolved; code: 268435846; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 14
 message: StaffApi cannot be resolved to a type; code: 16777218; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 34
 message: StaffApi cannot be resolved to a type; code: 16777218; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 34
 message: StaffApi cannot be resolved to a type; code: 16777218; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 39
 message: StaffApi cannot be resolved to a type; code: 16777218; resource: /workspaces/biz-module-approval/biz-module-approval-srv/src/main/java/com/xx/approval/factory/ActualApproverGetterStrategy.java; line: 152

ifrankwang avatar Mar 16 '24 08:03 ifrankwang

In my case, there's an annotation com.baomidou.mybatisplus.annotation.TableField included in my dto package:

image

Which located in library mybatis-plus-annotation-3.5.5.jar image

but itself has a dependency from package org.apache.ibatis.type, which comes from another library mybatis-3.5.15.jar image image

and I only included the mybatis-plus-annotation-3.5.5.jar library in my dto layer of pom.xml image

as soon as I remove the com.baomidou.mybatisplus.annotation.TableField annotation from the DTO class, the errors vanished, so I'm guessing the plugin is trying to get all dependencies of class (both directly and indirectly), so when it can't get the indirectly dependencies, the related errors pops up.

Hopes anyone facing the same issue found my comments helpful 😉

ifrankwang avatar Apr 14 '24 13:04 ifrankwang