Skip to content

Failed to run config for nvim-java error #374

Closed as duplicate
Closed as duplicate

Description

@4r73m190r0s

When I open my Nvim I get this error:

Failed to run `config` for nvim-java                                                                                                                                                                                                                                                                                      ...zy/mason.nvim/lua/mason-core/package/AbstractPackage.lua:132: attempt to index local 'location' (a function value)                                                                                                                                                                                                     # stacktrace:                                                                                                                                                  - mason.nvim\lua\mason-core\package\AbstractPackage.lua:132 _in_ **get_receipt**                                                                             - mason.nvim\lua\mason-core\package\AbstractPackage.lua:168 _in_ **get_installed_version**                                                                   - lua/config/lazy.lua:25                                                                                                                                     - init.lua:2                  

My config files:

vim.lsp.enable({ "jdtls" }) -- Error persists with or without this line

lazy.nvim specs:

nvim-java

return { 
  "nvim-java/nvim-java",
  dependencies = {
    "williamboman/mason.nvim",
    "williamboman/mason-lspconfig.nvim",
    "neovim/nvim-lspconfig",
    "mfussenegger/nvim-dap"
  },
  opts = {
    jdk = { auto_install = false }
  },
  priority = 100
}   

mason

return { "mason-org/mason.nvim" }

Activity

  1. yamafaktory commented on May 7, 2025

    @yamafaktory

    Hi, I'm also getting some errors which are triggered by the call to require('java').setup({}):

    Error detected while processing /home/davy/.config/nvim/init.lua:
    E5113: Error while calling lua chunk: ...zy/mason.nvim/lua/mason-core/package/AbstractPackage.lua:132: attempt to index local 'location' (a function value)
    stack traceback:
            ...zy/mason.nvim/lua/mason-core/package/AbstractPackage.lua:132: in function 'get_receipt'
            ...zy/mason.nvim/lua/mason-core/package/AbstractPackage.lua:168: in function 'get_installed_version'
            ...local/share/nvim/lazy/nvim-java/lua/java/utils/mason.lua:18: in function 'is_available'
            ...local/share/nvim/lazy/nvim-java/lua/java/utils/mason.lua:49: in function 'is_outdated'
            ...share/nvim/lazy/nvim-java/lua/java/startup/mason-dep.lua:27: in function 'install'
            /home/davy/.local/share/nvim/lazy/nvim-java/lua/java.lua:35: in function 'setup'
            /home/davy/.config/nvim/init.lua:545: in main chunk

    This is very likely related to Mason's breaking changes https://github.com/mason-org/mason-lspconfig.nvim/blob/main/CHANGELOG.md#200-2025-05-06 .

  2. mdudzinski commented on May 7, 2025

    @mdudzinski

    Hi, I'm also getting some errors which are triggered by the call to require('java').setup({}):

    Error detected while processing /home/davy/.config/nvim/init.lua:
    E5113: Error while calling lua chunk: ...zy/mason.nvim/lua/mason-core/package/AbstractPackage.lua:132: attempt to index local 'location' (a function value)
    stack traceback:
    ...zy/mason.nvim/lua/mason-core/package/AbstractPackage.lua:132: in function 'get_receipt'
    ...zy/mason.nvim/lua/mason-core/package/AbstractPackage.lua:168: in function 'get_installed_version'
    ...local/share/nvim/lazy/nvim-java/lua/java/utils/mason.lua:18: in function 'is_available'
    ...local/share/nvim/lazy/nvim-java/lua/java/utils/mason.lua:49: in function 'is_outdated'
    ...share/nvim/lazy/nvim-java/lua/java/startup/mason-dep.lua:27: in function 'install'
    /home/davy/.local/share/nvim/lazy/nvim-java/lua/java.lua:35: in function 'setup'
    /home/davy/.config/nvim/init.lua:545: in main chunk
    This is very likely related to Mason's breaking changes https://github.com/mason-org/mason-lspconfig.nvim/blob/main/CHANGELOG.md#200-2025-05-06 .

    I'm running into the same issue

  3. Zeioth commented on May 7, 2025

    @Zeioth
    Contributor

    Image

    @s1n7ax Same here. Seems to be incompatible with mason 2.0.

    Failed to run `config` for nvim-java
    
    ...zy/mason.nvim/lua/mason-core/package/AbstractPackage.lua:132: attempt to index local 'location' (a function value)
    
    # stacktrace:
      - /mason.nvim/lua/mason-core/package/AbstractPackage.lua:132 _in_ **get_receipt**
      - /mason.nvim/lua/mason-core/package/AbstractPackage.lua:168 _in_ **get_installed_version**
      - lua/base/utils/init.lua:318
    

    Full mason v2 changelog:
    https://github.com/mason-org/mason.nvim/blob/main/CHANGELOG.md

  4. Zeioth commented on May 7, 2025

    @Zeioth
    Contributor

    PR shipped. It can be tested here:
    #376

  5. Kabil777 commented on May 8, 2025

    @Kabil777

    @Zeioth I've made the change locally, but I'm still encountering different error like

    Image

  6. cmon1701 commented on May 8, 2025

    @cmon1701

    @Zeioth I can confirm that it works!!

    I have another issue, but I don't know if it is related to this issue, this PR or nvim-java in general:
    When I start Neovim, Mason opens and although it shows jdtls as installed, it tries to install it and repots the download error [4/4] Failed to download file "https://download.eclipse.org/jdtls/milestones/1.43.0/jdt-language-server-1.43.0-202504011455.tar.gz"

  7. Kabil777 commented on May 8, 2025

    @Kabil777

    @Zeioth
    Additionally I have changed 2 files to make it work and they were

    nvim-java-core/lua/java-core/ls/servers/jdtls/init.lua

    from this method

    local jdk = mason_reg.get_package('openjdk-17')
    
    if jdk:is_installed() then
    local java_home = vim.fn.glob(path.join(jdk:get_install_path(), '/jdk-17*'))
    local java_bin = path.join(java_home, '/bin')
    
    base_config.cmd_env = {
    ['PATH'] = vim.fn.getenv('PATH') .. ':' .. java_bin,
    ['JAVA_HOME'] = java_home,
    }
    end
    

    to

    local jdk = mason_reg.get_package('openjdk-17')
    
    if jdk:is_installed() then
    local java_home = vim.fn.glob(vim.fn.expand("$MASON/packages/openjdk-17/jdk-17*"))
    local java_bin = path.join(java_home, '/bin')
    
    base_config.cmd_env = {
    ['PATH'] = vim.fn.getenv('PATH') .. ':' .. java_bin,
    ['JAVA_HOME'] = java_home,
    }
    end
    

    nvim-java-core/lua/java-core/utils/mason.lua

    local mason_registry = require('mason-registry')
    
    local M = {}
    
    ---Returns the path to the package in mason packages
    ---@param pkg_name string
    ---@return string | nil
    function M.get_pkg_path(pkg_name)
    -- CHANGED: Replaced deprecated get_install_path() with manually constructed path
    local mason_data_path = vim.fn.stdpath("data") .. "/mason/packages/" .. pkg_name
    return mason_data_path
    end
    
    ---Returns true if the package is installed in mason
    ---@param pkg_name string
    ---@return boolean
    function M.is_pkg_installed(pkg_name)
    -- CHANGED: Used pcall to safely check if package exists and avoid runtime errors
    local ok, pkg = pcall(mason_registry.get_package, pkg_name)
    return ok and pkg:is_installed()
    end
    
    ---Returns the shared artifact path for a given package
    ---@param pkg_name string name of the package to get the path of
    ---@return string # path to the shared artifact directory of the package
    function M.get_shared_path(pkg_name)
    -- CHANGED: Replaced use of shell variable $MASON with Neovim's standard path function
    local mason_share_path = vim.fn.stdpath("data") .. "/mason/share/" .. pkg_name
    return mason_share_path
    end
    
    return M
    

    this configuration will replace mason2.0.0 api than older mason braking api changes and it works well for me

  8. Zeioth commented on May 8, 2025

    @Zeioth
    Contributor

    @Kabil777 I've reviewed and it looks good to me. I've also looked into every other sub-project of nvim-java and I can't find any other change required.

    Why not sending the PR to https://github.com/nvim-java/nvim-java-core ?

  9. Kabil777 commented on May 8, 2025

    @Kabil777

    Here is my PR to nvim-java-core

    I'm also looking for nvim-javagenie feature in nvim-java which provides feature of jpa-buddy plugin in intelij-idea

  10. 4r73m190r0s commented on May 8, 2025

    @4r73m190r0s
    Author

    Can someone help how to tie nvim-java with lspconfig and mason.nvim?

    From the main page of GitHub

    Setup nvim-java before lspconfig

    Here is my config:

    -- nvim\lua\plugins\nvim-java.lua
    return {
      "nvim-java/nvim-java",
      dependencies = {
        "neovim/nvim-lspconfig",
      }
    }
    -- nvim\lua\plugins\lsp.lua
    return {
      {
        "neovim/nvim-lspconfig"
      },
      {
        "mason-org/mason.nvim",
        opts = {}
      },
      {
        "mason-org/mason-lspconfig.nvim",
        dependencies = {
          "neovim/nvim-lspconfig",
          "mason-org/mason.nvim"
        },
        opts = {
          ensure_installed = {
            "jdtls"
          }
        }
      }
    }

    I don't know where to call require('java').setup()?

  11. JameChou commented on May 9, 2025

    @JameChou

    @cmon1701 I got the same issue.

    https://download.eclipse.org/jdtls/milestones/1.43.0/jdt-language-server-1.43.0-202504011455.tar.gz the url verson number is not correct, it should be 1.46.1.

    Check Mason 2.0 realease note.

    local registry = require("mason-registry")
    local pkg = registry.get_package("lua-language-server")
    local latest_version = pkg:get_latest_version()

    get_latest_version() will return package lastest version.

    PR

    local installed_version = pkg:get_installed_version()
    is_installed = installed_version == package_version

    change to

    local installed_version = pkg:get_installed_version()
    is_installed = installed_version == pkg:get_lateset_version()
  12. Zeioth commented on May 10, 2025

    @Zeioth
    Contributor

    @JameChou If you keep backtracing, you see versions are hardcoded, and taken from the versions file here, unless the user override with his own config.

    Your code works, but it seems it is not what the developer intended originally. Probably as a mean to avoid remote breaking changes.

  13. Morph01 commented on May 10, 2025

    @Morph01

    Hello,

    The jdtls 1.46.1 is now available thanks to @s1n7ax (nvim-java/release-jdtls#3).

    A temporary solution is to specify the jdtls version:

    -- nvim/lua/plugins/nvim-java.lua
    return {
        "nvim-java/nvim-java",
        lazy = false,
        config = function()
            require("java").setup({
                jdtls = {
                    version = "v1.46.1",
                },
            })
        end,
    }

    It will download directly the 1.46.1 (bypassing the wrong 1.43.0 url).

    But I cannot have the lombok support. The annotation @Data is not autocompleted and all the boilerplate methods are not recognized.
    Even if it is installed in the Mason menu, when I open a .java file, the LSP jdtls says:

    E The import lombok cannot be resolved Java (268435846) [3, 8]
    E Data cannot be resolved to a type Java (16777218) [10, 5]

    PS:
    When I open a .java file, I have these warnings concerning the dap:

    dap configuration failed                                                                                                                           
    RPC[Error] code_name = MethodNotFound, message = "No delegateCommandHandler for vscode.java.resolveMainClass"                                      
    stack traceback:                                                                                                                                   
            ...al/share/nvim/lazy/nvim-java/lua/java/handlers/error.lua:18: in function 'error_handler'                                                
            ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:32: in function 'callback'                                                     
            ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:74: in function 'handler'                                                      
            /usr/share/nvim/runtime/lua/vim/lsp/client.lua:682: in function ''                                                                         
            vim/_editor.lua: in function <vim/_editor.lua:0>                                                                                           
    Press ENTER or type command to continue                                                                                                            
    Error executing vim.schedule lua callback: ...al/share/nvim/lazy/nvim-java/lua/java/handlers/error.lua:28:                                         
    dap configuration failed                                                                                                                           
    RPC[Error] code_name = MethodNotFound, message = "No delegateCommandHandler for vscode.java.resolveMainClass"                                      
    stack traceback:                                                                                                                                   
            ...al/share/nvim/lazy/nvim-java/lua/java/handlers/error.lua:18: in function 'error_handler'                                                
            ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:32: in function 'callback'                                                     
            ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:74: in function 'handler'                                                      
            /usr/share/nvim/runtime/lua/vim/lsp/client.lua:682: in function ''                                                                         
            vim/_editor.lua: in function <vim/_editor.lua:0>                                                                                           
    stack traceback:                                                                                                                                   
            [C]: in function 'error'                                                                                                                   
            ...al/share/nvim/lazy/nvim-java/lua/java/handlers/error.lua:28: in function 'error_handler'                                                
            ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:32: in function 'callback'                                                     
            ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:74: in function 'handler'                                                      
            /usr/share/nvim/runtime/lua/vim/lsp/client.lua:682: in function ''                                                                         
            vim/_editor.lua: in function <vim/_editor.lua:0>                                                                                           
    Press ENTER or type command to continue

    All of these errors are due to the recent migration to Mason 2.0.0.

  14. JameChou commented on May 11, 2025

    @JameChou

    @Zeioth You're right. This was just a temporary fix, but now your PR has been merged into the main branch. Thanks for your suggestions and contributions.

  15. uuuulopta commented on May 11, 2025

    @uuuulopta

    i am using lazyvim and can't upgrade mason to 2.0 yet, so I set nvim-java to the latest version before the commit, howver i get this weird bug when I do lsp hover for a symbol i get "no information avaliable" message, even though it returns information. Anyone had this issue?

  16. Zeioth commented on May 11, 2025

    @Zeioth
    Contributor

    @uuuulopta you are likely missing mason-lspconfig.nvim v2

  17. Kabil777 commented on May 11, 2025

    @Kabil777

    @Zeioth There is still an unresolved issue in nvim-java/core: it is not yet compatible with Mason v2.0.0.

  18. MrMic commented on May 12, 2025

    @MrMic

    When will this bug be fixed?

    KR

  19. s1n7ax commented on May 13, 2025

    @s1n7ax
    Member
  20. HakuFlaku commented on May 14, 2025

    @HakuFlaku

    @Morph01

    PS: When I open a .java file, I have these warnings concerning the dap:

    dap configuration failed
    RPC[Error] code_name = MethodNotFound, message = "No delegateCommandHandler for vscode.java.resolveMainClass"
    stack traceback:
    ...al/share/nvim/lazy/nvim-java/lua/java/handlers/error.lua:18: in function 'error_handler'
    ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:32: in function 'callback'
    ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:74: in function 'handler'
    /usr/share/nvim/runtime/lua/vim/lsp/client.lua:682: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
    Press ENTER or type command to continue
    Error executing vim.schedule lua callback: ...al/share/nvim/lazy/nvim-java/lua/java/handlers/error.lua:28:
    dap configuration failed
    RPC[Error] code_name = MethodNotFound, message = "No delegateCommandHandler for vscode.java.resolveMainClass"
    stack traceback:
    ...al/share/nvim/lazy/nvim-java/lua/java/handlers/error.lua:18: in function 'error_handler'
    ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:32: in function 'callback'
    ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:74: in function 'handler'
    /usr/share/nvim/runtime/lua/vim/lsp/client.lua:682: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
    stack traceback:
    [C]: in function 'error'
    ...al/share/nvim/lazy/nvim-java/lua/java/handlers/error.lua:28: in function 'error_handler'
    ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:32: in function 'callback'
    ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:74: in function 'handler'
    /usr/share/nvim/runtime/lua/vim/lsp/client.lua:682: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
    Press ENTER or type command to continue

    All of these errors are due to the recent migration to Mason 2.0.0.

    Is #293 related to this at all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions