redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 430 forks source link

imports are not resolved in maven multi module project #3201

Open sagIoTPower opened 1 year ago

sagIoTPower commented 1 year ago

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
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

snjeza commented 1 year ago

@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>
sagIoTPower commented 1 year ago

@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.

snjeza commented 1 year ago

@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

JACKROMER commented 8 months ago

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.

snjeza commented 8 months ago

@sagIoTPower Could you provide a project example?

sagIoTPower commented 8 months ago

@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

ifrankwang commented 6 months ago

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 commented 6 months ago

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 commented 5 months ago

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 😉