vscode-java: Cannot import maven project from workspace

Everytime I clean up workspace by hitting “F1” and select “Java: Clean Language Server Workspace”, redhat stuck on importing Java maven project

Environment
  • Operating System: WIN10 x64
  • JDK version: 17.0.6
  • Visual Studio Code version: 1.75.1
  • Java extension version: v1.15 and v1.16.2023022803 (prerelease)
!SESSION 2023-02-28 11:27:57.191 -----------------------------------------------
eclipse.buildId=unknown
java.version=17.0.6
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments:  -data c:\Users\Daniel\AppData\Roaming\Code\User\workspaceStorage\6cc28fff9974d0c32371623240d7c1b3\redhat.java\jdt_ws

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:58.932
!MESSAGE class org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin is started

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.157
!MESSAGE Main thread is waiting

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.195
!MESSAGE >> initialize

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.199
!MESSAGE Initializing Java Language Server 1.21.0.202302280807

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.906
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.906
!MESSAGE Non-Static Commands: [java.edit.organizeImports, java.project.refreshDiagnostics, java.project.import, java.navigate.openTypeHierarchy, java.project.removeFromSourcePath, java.project.listSourcePaths, java.project.resolveStackTraceLocation, java.project.getAll, java.reloadBundles, java.project.isTestFile, java.edit.handlePasteEvent, java.project.getClasspaths, java.navigate.resolveTypeHierarchy, java.edit.stringFormatting, java.project.getSettings, java.project.updateSourceAttachment, java.project.resolveWorkspaceSymbol, java.project.upgradeGradle, java.project.createModuleInfo, java.protobuf.generateSources, java.project.resolveSourceAttachment, java.project.addToSourcePath, java.completion.onDidSelect]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.907
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.908
!MESSAGE Non-Static Commands: [java.intellicode.enable]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.909
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.909
!MESSAGE Non-Static Commands: [vscode.java.checkProjectSettings, vscode.java.isOnClasspath, vscode.java.fetchUsageData, vscode.java.validateLaunchConfig, vscode.java.resolveInlineVariables, vscode.java.resolveClassFilters, vscode.java.resolveMainMethod, vscode.java.resolveClasspath, vscode.java.resolveBuildFiles, vscode.java.resolveMainClass, vscode.java.updateDebugSettings, vscode.java.resolveSourceUri, vscode.java.fetchPlatformSettings, vscode.java.buildWorkspace, vscode.java.startDebugSession, vscode.java.inferLaunchCommandLength, vscode.java.resolveElementAtSelection, vscode.java.resolveJavaExecutable]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.911
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.911
!MESSAGE Non-Static Commands: [java.project.refreshLib, java.project.list, java.project.generateJar, java.project.getMainClasses, java.getPackageData, java.resolvePath]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.913
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.913
!MESSAGE Non-Static Commands: [vscode.java.test.findJavaProjects, vscode.java.test.findTestPackagesAndTypes, vscode.java.test.findTestTypesAndMethods, vscode.java.test.resolvePath, vscode.java.test.findTestLocation, vscode.java.test.get.testpath, vscode.java.test.findDirectTestChildrenForClass, vscode.java.test.navigateToTestOrTarget, vscode.java.test.junit.argument, vscode.java.test.generateTests]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.914
!MESSAGE Static Commands: []

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.915
!MESSAGE Non-Static Commands: [java.maven.initializeSearcher, java.maven.searchArtifact, java.maven.addDependency, java.maven.controlContext]

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.923
!MESSAGE Starting org.eclipse.m2e.core

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:27:59.924
!MESSAGE Started org.eclipse.m2e.core 1ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:28:00.011
!MESSAGE ProjectRegistryRefreshJob finished 87ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:28:00.012
!MESSAGE Starting org.eclipse.buildship.core

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:28:00.039
!MESSAGE Started org.eclipse.buildship.core 26ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:28:00.045
!MESSAGE RepositoryRegistryUpdateJob finished 1ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:28:00.059
!MESSAGE Creating the Java project jdt.ls-java-project

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:28:00.059
!MESSAGE >> initialized

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:28:00.223
!MESSAGE Finished creating the Java project jdt.ls-java-project

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-02-28 11:28:00.825
!MESSAGE Importing Maven project(s)

On the build status console:

image

Client log:

{
  message: 'Starting Java server with: c:\\Program Files\\Java\\jdk-17\\bin\\java --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.nio.fs=ALL-UNNAMED -Declipse.application=org.eclipse.jdt.ls.core.id1 -Dosgi.bundles.defaultStartLevel=4 -Declipse.product=org.eclipse.jdt.ls.core.product -Djava.import.generatesMetadataFilesAtProjectRoot=false -Dfile.encoding=utf8 -XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms1G -Xlog:disable -javaagent:c:\\Users\\Daniel\\.vscode\\extensions\\redhat.java-1.16.2023022803-win32-x64\\lombok\\lombok-1.18.24.jar -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=c:\\Users\\Daniel\\AppData\\Roaming\\Code\\User\\workspaceStorage\\6cc28fff9974d0c32371623240d7c1b3\\redhat.java -jar c:\\Users\\Daniel\\.vscode\\extensions\\redhat.java-1.16.2023022803-win32-x64\\server\\plugins\\org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar -configuration c:\\Users\\Daniel\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.16.2023022803\\config_win -data c:\\Users\\Daniel\\AppData\\Roaming\\Code\\User\\workspaceStorage\\6cc28fff9974d0c32371623240d7c1b3\\redhat.java\\jdt_ws',
  level: 'info',
  timestamp: '2023-02-28 11:27:56.809'
}
{
  message: 'WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector\r\n',
  level: 'info',
  timestamp: '2023-02-28 11:27:56.910'
}

Running extension:

image

Even I manually delete workspace folders, issue will not be solved.

Current Result

Maven project cannot be imported into VScode, it stuck in 31% forever. The only way to solve it is to remove the entire repository and download it again. And it only works for 1 time. If I clean the workspace again, it will stuck at import maven project again.

Expected Result

Import successfully

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 43 (28 by maintainers)

Most upvoted comments

Then clean JLS workspace and for me it takes forever.

@karlvr I can’t reproduce the issue. Could you attach your server log ?

I have reproduced the issue. I’m trying to fix it.

@snjeza thank you very much, I have installed the .vsix using command-shift-p “Extensions: Install from VSIX” and verified that the extension is installed and at v1.27.3.

Configuration Time to complete Opening Java Projects
v1.27.3, no settings.json tweaks 2:25
v1.25.1, no settings.json tweaks forever
v1.27.3, "java.import.generatesMetadataFilesAtProjectRoot": true, in settings.json 2:15
v1.25.1, "java.import.generatesMetadataFilesAtProjectRoot": true in settings.json 2:12
v1.27.3, "java.import.generatesMetadataFilesAtProjectRoot": true, "java.project.resourceFilters": ..., "java.import.exclusions": ... in settings.json 1:55–2:10
v1.25.1, "java.import.generatesMetadataFilesAtProjectRoot": true, "java.project.resourceFilters": ..., "java.import.exclusions": ... in settings.json 2:05—2:25
v1.27.3, "java.project.resourceFilters": ..., "java.import.exclusions": ... in settings.json 2:15–2:25
v1.25.1, "java.project.resourceFilters": ..., "java.import.exclusions": ... in settings.json forever

Notes on method:

  • When I toggle the "java.import.generatesMetadataFilesAtProjectRoot": true, in settings.json I delete .project, .classpath, .factorypath and .settings each time after the window reloads (see next)… as their presence even without that setting seems to help (not scientifically observed).
  • Between each test I’m running the clean Java Language Server workspace. I’m measuring from pressing “Reload and Delete” on the clean and seeing the window refresh to the Java loading spinner stopping when I have a .java file open.
  • I repeated tests a couple of times, so I’ve given a range (or no range if they were really close)

Conclusion:

You’ve fixed it and I’m very happy. It seems there’s a slight advantage for the settings.json tweaks that I tried; I’m not 100% sure about that, but I think I’ll run with the set of three!

	"java.project.resourceFilters": [
		"node_modules",
		"\\.git"
	],
	"java.import.exclusions": [
		"**/node_modules/**",
		"**/.metadata/**",
		"**/archetype-resources/**",
		"**/META-INF/maven/**",
	],
	"java.import.generatesMetadataFilesAtProjectRoot": true,

I converted from Eclipse a few years ago and my life has been so much better, and now it’s better again. Thank you, and everyone, for your efforts.

@karlvr Could you try to test VS Code 1.27.3?

@karlvr Could you try VS Code 1.27.2?

@karlvr Could you show your settings.json?

Is there a way to ignore folders, e.g. node_modules?

You can set

"java.import.exclusions": [
    "**/node_modules/**",
    "**/.metadata/**",
    "**/archetype-resources/**",
    "**/META-INF/maven/**",
  ],