imports are not resolved in maven multi module project
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 ...
- I open the project in vcode (extension pack vscjava.vscode-java-pack) and
- navigate to the module
mqtt-mapping-extensionand - open class
mqtt-mapping extension/src/main/java/mqtt/mapping/processor/extension/external/ProcessorExtensionCustomEvent.java - I see the following errors:
The import mqtt.mapping.model cannot be resolvedJava(268435846) mqtt.mappingin the source editor:
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
- clone the project (https://github.com/SoftwareAG/cumulocity-dynamic-mqtt-mapper/tree/develop)
- navigate to the module
mqtt-mapping-extensionand open classmqtt-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
@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 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.
@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
i got the same problem.
my multi mudules pom file like this
compile error is this :The import com.fajiajia.cloudcommon cannot be resolved,
but when i open this error file, it disappear soon,
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.
@sagIoTPower Could you provide a project example?
@snjeza: I created a branch to demonstrate the error.
bug-vcode-java
In vscode it does not work:
but the same works in intellij:
i got the same problem. my multi mudules pom file like this
compile error is this :The import com.fajiajia.cloudcommon cannot be resolved,
but when i open this error file, it disappear soon,
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
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
In my case, there's an annotation com.baomidou.mybatisplus.annotation.TableField included in my dto package:
Which located in library mybatis-plus-annotation-3.5.5.jar
but itself has a dependency from package org.apache.ibatis.type, which comes from another library mybatis-3.5.15.jar
and I only included the mybatis-plus-annotation-3.5.5.jar library in my dto layer of pom.xml
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 😉
compile error is this :The import com.fajiajia.cloudcommon cannot be resolved,
but when i open this error file, it disappear soon,
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.