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

Gradle "includeBuild" no longer recognizes imported classes in the IDE

Open lRawd opened this issue 1 year ago • 3 comments

When utilizing "includeBuild" in the settings.gradle file, the IDE no longer recognizes java imports/objects from the included project. Compiling in gradle via the command line continues to work as expected.

Environment
  • Operating System: Windows
  • JDK version: 1.8/17
  • Visual Studio Code version: 1.88.1
  • Java extension version: 1.29
Steps To Reproduce
  1. Run gradle init to generate a java library called 'inc1'
  2. Run gradle init to generate a java library called 'inc2'
  3. Add 'group="inc2"' to inc2 build.gradle
  4. Add includeBuild '..\\inc2' to the inc1 settings.gradle file
  5. Add implementation "inc2:lib:1.0.0" to inc1 build.gradle dependencies
  6. Create class Lib2.java in the inc2 project
  7. Import and instantiate the Lib2 object in the inc1 project
  8. Run gradle assemble in inc1 and verify success
  9. Open inc1 in VSCode and verify it can not locate the Lib2 object

[Sample Project]

Current Result

The Lib2 import cannot be resolved in VSCode

Expected Result

The Lib2 import can be resolved in VSCode

Additional Informations

lRawd avatar Apr 24 '24 19:04 lRawd

I was also able to reproduce this issue using the provided same project with a slightly newer version of the plugin.

Environment
  • Operating System: Windows
  • JDK version: 17
  • Visual Studio Code version: 1.88.1
  • Java extension version: 1.30.0

cinnamonFox avatar Apr 29 '24 17:04 cinnamonFox

If I update my preferences to generate metadata at root("java.import.generatesMetadataFilesAtProjectRoot": true), close vscode, delete all metadata, import the project into eclipse, close eclipse, then relaunch vscode, and clean the java workspace, it seems to recognize the imported classes. I have to re-clean the workspace everytime I re-launch vscode to get it to recognize the imported classes, otherwise it complains about Project 'inc1-lib' is missing required Java project: 'inc2-lib' which are the names of the projects that were imported into eclipse.

lRawd avatar Apr 29 '24 22:04 lRawd

Replacing my .project file with the one generated in eclipse seems to be what is fixing the issue. I'm not sure what side effects there are from using the eclipse version in vscode.

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>inc1-lib</name>
	<comment>Project inc1-lib created by Buildship.</comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
	</natures>
	<filteredResources>
		<filter>
			<id>1714428560210</id>
			<name></name>
			<type>30</type>
			<matcher>
				<id>org.eclipse.core.resources.regexFilterMatcher</id>
				<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
			</matcher>
		</filter>
	</filteredResources>
</projectDescription>

lRawd avatar Apr 30 '24 14:04 lRawd