Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional source directories are not put on classpath #3544

Open
RolKau opened this issue Mar 25, 2024 · 2 comments
Open

Additional source directories are not put on classpath #3544

RolKau opened this issue Mar 25, 2024 · 2 comments

Comments

@RolKau
Copy link

RolKau commented Mar 25, 2024

Additional source directories that are included using the build-helper-maven-plugin in a Maven project seem to not be made available to the language server, and are thus not picked up by for instance Go To Declaration and Find References.

Consider the attached example project, consisting of three leaf projects: Child1, Child2 and Child3, organized in two parent projects: ParentA and ParentB, where Child3 has a dependency on Child2, and Child2 has a dependency on Child1.

In the first iteration, stored in before/, Child1 and Child2 is organized under ParentA, and Child 3 is organized under ParentB. In the second iteration, stored in after/, Child2 is merged with Child3, but to avoid changes in the project history, the files are still kept under ParentA's directory and included in Child3 using build-helper-maven-plugin.

Environment
  • Operating System: Ubuntu Focal (20.04)
  • JDK version: OpenJDK 17.0.10
  • Visual Studio Code version: 1.87.2
  • Java extension version: 1.28.1
Steps To Reproduce
  1. Observe that the project in the directory before/ can be successfully compiled with mvn --also-make --batch-mode without any warnings.
  2. Start code before/project.code-workspace
  3. Navigate to parentB/child3/src/main/java/com/example/Qux.java
  4. Put the caret on the declaration of Bar b, right-click and select Go to definition.
  5. The file Bar.java opens
  6. Observe that the project in the directory after/ can be successfully compiled with mvn --also-make --batch-mode without any warnings.
  7. Start code after/project.code-workspace
  8. Navigate to parentB/child3/src/main/java/com/example/Qux.java
  9. Put the caret on the declaration of Bar b.
  10. Notice that it now gives the problem "Bar cannot be resolved to a type".
Current Result

In step 10, the class Bar cannot be found.

Expected Result

Step 10 should be like step 5, that the file Bar.java was opened when Go to definition was invoked.

Additional Information

issue-3544.zip

@cyberphone
Copy link

Maybe related to #3581

@RolKau
Copy link
Author

RolKau commented Apr 24, 2024

Indeed; thank you very much @cyberphone! Adding the paths as a variable in .project and .classpath seems to be a work-around. To summarize for other readers, the steps are:

  1. Define in .project for child3 a <variable> tag which refers to ${PROJECT_LOC}/../.. (or whichever relative path outside of the current project source tree you want)

  2. Define in .project for child3 a <link> tag that correlates a location relative to this variable which contains the extra source tree you want to add, with a non-existing directory name, e.g. child2_src_main_java.

  3. Add in .classpath for child3 a <classpathentry> tag similar to the one for src/main/java, but instead refering to the non-existing directory called child2_src_main_java that was created in step 2.

I have updated the example project to illustrate how this can be done in a Maven project.

issue-3544-update1.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants