Skip to content
Srinesh Nisala edited this page Jun 10, 2024 · 8 revisions

⛔ How to clean rebuild

Solution

Unfortunately, we don't have command to auto update the classpath when you change dependencies, or jdk. Without force rebuild, changes will not be applied. So for now, you can manually remove following files.

In the project, remove,

  • .classpath
  • .project

In cache, remove,

  • $HOME/.cache/jdtls
  • $HOME/.cache/nvim/jdtls

Cannot find package "xxxxx"

Solution

This issue occurs due to the way you have configured Mason.nvim. Follow the instructions below to correctly configure Mason.nvim using Lazy.nvim.

Method 1: use opts instead of config function to setup mason

return {
	'williamboman/mason.nvim',
	opts = {
		ui = {
			icons = {
				package_installed = '',
				package_pending = '',
				package_uninstalled = '',
			},
		},
	},
	-- use OPTS property to pass the configuration
	-- lazy vim call the setup function for you

	-- config = function()
	-- 	require('mason').setup({})
	-- end
	-- ^^^^^^^^^^^^^^^^ DON'T DO THIS
}

Method 2: If you have complex configuration inside config, you can pass a function to opts

return {
	'williamboman/mason.nvim',
	opts = function()
		-- do all your complex stuff here

		return {
			ui = {
				icons = {
					package_installed = '',
					package_pending = '',
					package_uninstalled = '',
				},
			},
		}
	end,
}

Method 3: If you really want to use config property for some reason, consider the default values

return {
	'williamboman/mason.nvim',
	config = function(_, opts)
		local conf = vim.tbl_deep_extend('keep', opts, {
			ui = {
				icons = {
					package_installed = '',
					package_pending = '',
					package_uninstalled = '',
				},
			},
		})
		-- ^^^^^ Here we are basically merge you configuration with OPTS
		-- OPTS contains configurations defined elsewhere like nvim-java

		require('mason').setup(conf)
	end,
}

⛔ LSP doesn't work on Maven projects

Solution
  • Go to the project and run
mvn eclipse:clean eclipse:eclipse
  • Now open the project in Neovim

Read this article for more information

To enrich the config, XXX should already be present

Solution

If you are getting this error, that means jdtls having a hard time finding the root of the project. This mostly happens when one of the parent directories is a git repository. If you are someone who manages the dotfiles in the $HOME directory using a git repository, you might see this error.

  • As a solution, you can make the current project root a git repository by running git init
  • Another option would be to pass the root markers when setting up nvim-java but not pass .git
require('java').setup({
  root_markers = {
    'settings.gradle',
    'settings.gradle.kts',
    'pom.xml',
    'build.gradle',
    'mvnw',
    'gradlew',
    'build.gradle',
    'build.gradle.kts'
  },
})
  • Make current folder a git repository
git init
  • Re-open neovim

⛔ How to remove noisy and annoying jdtls notifications

Solution

If you find following notifications annoying, first of all, this has nothing to do with this plugin, BUT you can simply remove them when you are setting up the language server.

image

Here is how you can do it.

require("lspconfig").jdtls.setup({
	handlers = {
		-- By assigning an empty function, you can remove the notifications
		-- printed to the cmd
		["$/progress"] = function(_, result, ctx) end,
	},
})

⛔ Disable OpenJDK-17 auto installation

Solution

We are installing jdk-17 because that's the recommended runtime to run jdtls. However, if you have jdk-17 already, you can use that instead. To disable auto install, set jdk.auto_install to false

require('java').setup({
  jdk = {
    auto_install = false,
  },
})

Unknown purl type: openvsx

Solution

This is not related to nvim-java but you can solve it by updating mason.nvim plugin.

Case of this error is, mason-registry recently added packages from openvsx registry. However, old mason.nvim plugin does not know how to process this registry type.