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

Test methods not working since jdtls version 1.28.0 #565

Closed
zenoli opened this issue Oct 1, 2023 · 10 comments
Closed

Test methods not working since jdtls version 1.28.0 #565

zenoli opened this issue Oct 1, 2023 · 10 comments

Comments

@zenoli
Copy link

zenoli commented Oct 1, 2023

LSP client configuration

{
  capabilities = {
    textDocument = {
      completion = {
        completionItem = {
          commitCharactersSupport = true,
          deprecatedSupport = true,
          insertReplaceSupport = true,
          insertTextModeSupport = {
            valueSet = { 1, 2 }
          },
          labelDetailsSupport = true,
          preselectSupport = true,
          resolveSupport = {
            properties = { "documentation", "detail", "additionalTextEdits", "sortText", "filterText", "insertText", "textEdit", "insertTextFormat", "insertTextMode" }
          },
          snippetSupport = true,
          tagSupport = {
            valueSet = { 1 }
          }
        },
        completionList = {
          itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data" }
        },
        contextSupport = true,
        dynamicRegistration = false,
        insertTextMode = 1
      }
    }
  },
  cmd = { "jdtls", "-configuration", "/home/dev/.cache/nvim/jdtls/java-pg/config", "-data", "/home/dev/.cache/nvim/jdtls/java-pg/workspace" },
  init_options = {
    bundles = { "/home/dev/.local/share/nvim/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-0.47.0.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/com.microsoft.java.test.plugin-0.39.0.jar", "/home/dev/.local/share
/nvim/mason/packages/java-test/extension/server/com.microsoft.java.test.runner-jar-with-dependencies.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-jupiter-api_5.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/
junit-jupiter-engine_5.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-jupiter-migrationsupport_5.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-jupiter-params_5.9.2.jar", "/home/dev/.local/share/nvim
/mason/packages/java-test/extension/server/junit-platform-commons_1.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-platform-engine_1.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-platform-launcher_1
.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-platform-runner_1.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-platform-suite-api_1.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/e
xtension/server/junit-platform-suite-commons_1.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-platform-suite-engine_1.9.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/junit-vintage-engine_5.9.2.jar", "/home/
dev/.local/share/nvim/mason/packages/java-test/extension/server/org.apiguardian.api_1.1.2.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/org.eclipse.jdt.junit4.runtime_1.3.0.v20220609-1843.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/
extension/server/org.eclipse.jdt.junit5.runtime_1.1.100.v20220907-0450.jar", "/home/dev/.local/share/nvim/mason/packages/java-test/extension/server/org.opentest4j_1.2.0.jar" }
  },
  root_dir = "/home/dev/sample-projects/java-pg",
  settings = {
    java = {
      signatureHelp = {
        enabled = true
      }
    }
  }
}

Eclipse.jdt.ls version

1.28.0

Steps to Reproduce

Gradle setup:

Output of ./gradlew --version:

------------------------------------------------------------
Gradle 7.4
------------------------------------------------------------

Build time:   2022-02-08 09:58:38 UTC
Revision:     f0d9291c04b90b59445041eaa75b2ee744162586

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.8.1 (Oracle Corporation 17.0.8.1+1)
OS:           Linux 5.15.0-84-generic amd64

Dependencies

dependencies {
    testImplementation 'junit:junit:4.13'
    testImplementation 'org.mockito:mockito-inline:4.0.0'
    testImplementation 'org.mockito:mockito-junit-jupiter:4.0.0'
}

Steps to reproduce:

  1. Open a java test file and run either of the following commands:
:lua require("jdtls.dap").test_class()
:lua require("jdtls.dap").test_nearest_method()
:lua require("jdtls.dap").pick_test()

Expected Result

Running/picking/debugging tests work as expected.

Actual Result

A notifiaction
 ERROR Error fetching test candidates: org/eclipse/jdt/ls/core/internal/hover/JavaElementLabels
appears.

Using :JdtShowLogs I could see the following:

!ENTRY org.eclipse.jdt.ls.core 4 2 2023-10-01 15:45:30.752                                                                                                        
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ls.core".                                                                            
!STACK 0                                                                                                                                                          
java.lang.NoClassDefFoundError: org/eclipse/jdt/ls/core/internal/hover/JavaElementLabels                                                                          
    at com.microsoft.java.test.plugin.model.builder.JavaTestItemBuilder.build(JavaTestItemBuilder.java:75)                                                        
    at com.microsoft.java.test.plugin.util.TestSearchUtils.findTestItemsInTypeBinding(TestSearchUtils.java:425)                                                   
    at com.microsoft.java.test.plugin.util.TestSearchUtils.findTestTypesAndMethods(TestSearchUtils.java:375)                                                      
    at com.microsoft.java.test.plugin.handler.TestDelegateCommandHandler.executeCommand(TestDelegateCommandHandler.java:60)                                       
    at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)                                    
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)                                                                                                
    at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)                           
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:613)                                                           
    at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)                                                             
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)                                                              
    at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)                                                               
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)                                                                                  
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)                                                                 
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)                                                                                   
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)                                                                              
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)                                                                     
Caused by: java.lang.ClassNotFoundException: org.eclipse.jdt.ls.core.internal.hover.JavaElementLabels cannot be found by com.microsoft.java.test.plugin_0.39.0    
    at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:541)                                                                     
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:536)                                                                            
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416)                                                                             
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)                                                                   
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)                                                                                            
    ... 16 more                                                                                                                                                   

The plugin org/eclipse/jdt/ls/core/internal/hover/JavaElementLabels does not exist in v.1.28.0, hence the error. It used to exist in 1.27.1. Version v.1.27.1 worked perfectly fine for me.

Let me know if this is a nvim-jdtls isssue or whether I should post the issue on v.1.28.0 directly.

And thanks for the awesome plugin :-)

@mfussenegger
Copy link
Owner

Did you try rebuilding java-debug and vscode-java-test?

JavaElementLabels and other classes were removed from eclipse.jdt.ls: eclipse-jdtls/eclipse.jdt.ls#2854
I suspect the debug components used it as runtime dependency.

@zenoli
Copy link
Author

zenoli commented Oct 3, 2023

I installed all three packages using Mason.
I already tried reinstalling all three of them but it didn't fix anything.

@mfussenegger
Copy link
Owner

Maybe mason uses incompatible packages. There's nothing to do in nvim-jdtls about this as far as I can tell

@zenoli
Copy link
Author

zenoli commented Oct 4, 2023

Thanks for looking into this.
You are right, it seems there is PR open in the vscode-java-test repo which will hopefully get merged soon.

Edit: The mentioned PR is actually merged and v0.40.0 is avaiable. However they don't seem to provide the extension on their github release page anymore, which is probably why we cannot access them via mason (the registry was reading those files).

Edit2: For all Mason users, the current workaround is to build java-test v0.40.0 from source (as explained in the README.md). I can confirm that this version is compatible with jdtls v1.28.0

@cladera
Copy link

cladera commented Dec 2, 2023

For Mason users this is what I did to disrupt my setup the least as possible:

  1. Go to Mason's java-test package folder ~/[MASON_PATH]/packages/java-test. Here you will find a handful of files and the extension folder that contains the jar files.
  2. Clone vscode-java-test repo
  3. Go inside the cloned repo and run:
    npm i
    npm run build-plugin
    
  4. Go up and make a copy of the original extension folder mv extension extension-bkp
  5. Create a symbolic link to the cloned repo:
ln -s ./vscode-java-test extension

That's it, relaunch nvim and you are good to go 😄

Note: If you inspect the manson-receipt.json you fill find explicit references to the jar files that point to the previous versions. It should be ok if you don't modify those because the plugin that uses them utilises a glob expression.

@alfonsoadiego
Copy link

Following @cladera sollution worked but I did had to update the target file definition on com.microsoft.java.test.target Eclipse repository for the 4.30 version in order to solve this problem when trying to build-plugin

Missing requirement: org.eclipse.jdt.ls.core 1.31.0.202312081723 requires 'osgi.bundle; org.eclipse.search.core 3.16.0' but it could not be found

@tobii-dev
Copy link

tobii-dev commented Dec 12, 2023

@cladera solution worked for me, but for anyone allergic to installing and building locally with npm (took over 1GB...): Someone has created a mason registry with downloads for java-test. In general, that seems like a cleaner solution: mason-org/mason-registry#3083 (comment)

This is how I use it in configuring jdtls:

--ftplugin/java.lua:

local function get_bundles()
	local mason_reg = require("mason-registry")
	local function get_adapter_bundle()
		local pkg = mason_reg.get_package("java-debug-adapter")
		local pkg_install_path = pkg:get_install_path()
		local pkg_jar_glob = pkg_install_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar"
		local pkg_jar = vim.fn.glob(pkg_jar_glob, 1);
		return pkg_jar
	end
	local function get_vscode_java_test_bundles()
		local pkg = mason_reg.get_package("java-test")
		local pkg_install_path = pkg:get_install_path()
		local pkg_jars_glob = pkg_install_path .. "/extension/server/*.jar"
		local pkg_jars = vim.fn.glob(pkg_jars_glob, 1);
		local pkg_jars_list = vim.split(pkg_jars, "\n")
		return pkg_jars_list
	end
	local bundles = {
		get_adapter_bundle(),
	};
	vim.list_extend(bundles, get_vscode_java_test_bundles())
	-- vim.notify("[JAVA bundles] " .. vim.inspect(bundles))
	return bundles
end


local config = {
	-- cmd = { ... },
	-- on_attach = ... ,
	-- rood_dir = ...,
	-- settings = { ... },
	-- ...

	-- Language server `initializationOptions`
	-- You need to extend the `bundles` with paths to jar files if you want to use additional eclipse.jdt.ls plugins.
	-- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
	init_options = {
		bundles = get_bundles(),
	},
}

jdtls.start_or_attach(config)

Not super clean to have in your config, but it works.

@IlyasYOY
Copy link

Seems like Mason installation works fine now.

#588 (comment)

@allancomar
Copy link

I tried today with versions:
installed version v1.32.0
homepage https://github.com/eclipse/eclipse.jdt.ls
languages Java
categories LSP
executables jdtls

  installed version 0.52.0                                  
  homepage          https://github.com/microsoft/java-debug 
  languages         Java                                    
  categories        DAP  

  installed version 0.39.0                                        
  homepage          https://github.com/microsoft/vscode-java-test 
  languages         Java                                          
  categories        DAP     

and I am getting the same error.
any idea of what I am missing?

@zenoli
Copy link
Author

zenoli commented Feb 23, 2024

@allancomar Have to tried java-test 0.40.0? It has been a while but IIRC the fix to my original issue was to move past 0.39.0 which you are using. The issue was that mason did not support updating to it until recently. In case you are using mason as well, try updating it. I also had to call :JdtlsWipeDataAndRestart afterwards but everything works fine now for me.

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

7 participants