georgewfraser / java-language-server

Java language server using the Java compiler API
MIT License
637 stars 125 forks source link

Multi-module maven project not working with the language server #195

Open madsvlad2 opened 3 years ago

madsvlad2 commented 3 years ago

I am experiencing an issue with the language server when using a multi-module maven project In this scenario, one child module is dependent on the other. An example can be found here: https://github.com/madsvlad2/java-example-project

When editing foo/src/main/java/com/test/project/foo/Foo.java (I use Vim with ALE), the package com.test.project.common is not found. The log output from the language server indicates failures with the maven dependency:list and dependency:sources goals

INFO    InferConfig mvnDependencies Running mvn --batch-mode validate dependency:list -DincludeScope=test -DoutputAbsoluteArtifactFilename=true ...
16:29:17.653    SEVERE  InferConfig mvnDependencies `mvn --batch-mode validate dependency:list -DincludeScope=test -DoutputAbsoluteArtifactFilename=true` returned 1
16:29:17.655    INFO    InferConfig mvnDependencies Running mvn --batch-mode validate dependency:sources -DincludeScope=test -DoutputAbsoluteArtifactFilename=true ...
16:29:18.988    SEVERE  InferConfig mvnDependencies `mvn --batch-mode validate dependency:sources -DincludeScope=test -DoutputAbsoluteArtifactFilename=true` returned 1`

Executing those maven commands from the command-line in the repository root does indeed fail, however I believe this a known short-coming of Maven with child modules and dependency-related goals. The recommended workaround I have seen is to include the compile phase so that the dependent child modules are available in the reactor when other phases are executed:

mvn --batch-mode compile validate dependency:list -DincludeScope=test -DoutputAbsoluteArtifactFilename=true

Will complete successfully, however, I am not sure of the validity in this. I am new to Maven, but I would guess the idea of executing the validate phase would be to avoid compilation and just ensure required dependencies (and sources) are available?

I modified InterConfig.java so that the Maven commands include the compile phase, but it still failed. Closer examination shows that the workspace root is being set to the child module: foo/pom.xml rather than the root pom.xml (this will also fail from the command-line).

I guess my question is whether this is an issue with Maven project management in the language server or if there is something structurally wrong with the project set-up? I can say that IntelliJ handles this project structure.

madsvlad2 commented 3 years ago

Looking a bit closer, I think the second issue (the child pom rather than the parent) is an ALE issue, not the language-server.

pborzenkov commented 2 years ago

Hey @madsvlad2 Were you able to find a solution for this problem? I'm hitting the same issue.

madsvlad2 commented 2 years ago

Pavel,

It's been a while since a looked into this issue, but I believe the problem for me was caused by how the ALE Vim plugin for Maven projects launches the language server.

It uses the POM file nearest the file being edited which for my multi-module Maven project will never by the root POM file.

I was going to try and locally modify the ALE code to test this theory, but never got around to it.

I hope this helps you...

On Thu, Dec 23, 2021, 6:11 AM Pavel Borzenkov @.***> wrote:

Hey @madsvlad2 https://github.com/madsvlad2 Were you able to find a solution for this problem? I'm hitting the same issue.

— Reply to this email directly, view it on GitHub https://github.com/georgewfraser/java-language-server/issues/195#issuecomment-1000330859, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUVM6RV5Z5S63YPE6YV2UETUSMUXRANCNFSM47RHTSFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>