mfussenegger / nvim-jdtls

Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
GNU General Public License v3.0
1k stars 62 forks source link

cannot jdtcompile for java 11 #551

Closed yimingwangdell closed 10 months ago

yimingwangdell commented 10 months ago

LSP client configuration

-- See :help vim.lsp.start_client for an overview of the supported config options. local config = { -- The command that starts the language server -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line cmd = { -- šŸ’€ -- '/usr/lib/jvm/java-20-openjdk/bin/java', -- or '/path/to/java17_or_newer/bin/java' -- depends on if java is in your $PATH env variable and if it points to the right version. 'java', '-Declipse.application=org.eclipse.jdt.ls.core.id1', '-Dosgi.bundles.defaultStartLevel=4', '-Declipse.product=org.eclipse.jdt.ls.core.product', '-Dlog.protocol=true', '-Dlog.level=ALL', '-Xmx1g', '--add-modules=ALL-SYSTEM', '--add-opens', 'java.base/java.util=ALL-UNNAMED', '--add-opens', 'java.base/java.lang=ALL-UNNAMED',

    -- šŸ’€
    '-jar',
    os.getenv("HOME") .. '/Downloads/jdtls26/plugins/org.eclipse.equinox.launcher_1.6.500.v20230717-2134.jar',
    -- os.getenv("HOME") .. '/Downloads/jdtls19/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar',

    -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                       ^^^^^^^^^^^^^^
    -- Must point to the                                                     Change this to
    -- eclipse.jdt.ls installation                                           the actual version

    -- šŸ’€
    '-configuration', os.getenv("HOME") .. '/Downloads/jdtls26/config_linux/',
    -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        ^^^^^^
    -- Must point to the                      Change to one of `linux`, `win` or `mac`
    -- eclipse.jdt.ls installation            Depending on your system.

    -- šŸ’€
    -- See `data directory configuration` section in the README
    '-data', os.getenv("HOME") .. '/workspace/jdtls'
},

-- šŸ’€
-- This is the default if not provided, you can remove it. Or adjust as needed.
-- One dedicated LSP server & client will be started per unique root_dir
root_dir = require('jdtls.setup').find_root({ 'build.gradle' }),

-- Here you can configure eclipse.jdt.ls specific settings
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- for a list of options
settings = {
    java = {
        configuration = {
            runtimes = {
                {
                    name = "JavaSE-11",
                    path = "/usr/lib/jvm/java-11-openjdk/",
                },
                {
                    name = "JavaSE-17",
                    path = "/usr/lib/jvm/java-17-openjdk/",
                },
            }
        }
    }
},

-- 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
--
-- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this
init_options = {
    bundles = {}
},

}

-- This starts a new client & server, -- or attaches to an existing client & server depending on the root_dir. require('jdtls').start_or_attach(config)

Eclipse.jdt.ls version

org.eclipse.equinox.launcher_1.6.500.v20230717-2134.jar

Steps to Reproduce

open a java file of project with java 11 and gradle 5.6.4

Expected Result

able to compile

Actual Result

in console Can't use Java 20.0.2 and Gradle 7.4.2 to import Gradle project

in log message = "Sep 6, 2023, 6:30:40 PM Error occured while building workspace. Details: \n message: The supplied phased action failed with an exception.\nExecution failed for task ':buildSrc:compileGroovy'.\nBUG! exception in phase 'semantic analysis' in source unit ..............................Unsupported class file major version 64\nUnsupported class file major version 64; code: 0; resource: ..............................;\n message: Can't use Java 20.0.2 and Gradle 7.4.2 to import Gradle project ....; code: 0; resource: ................................; line: 1", type = 1 }

question

I have no idea why it use 20.0.2 and 7.4.2 ?? I haven't install them though. is it a BUG as log said? is java 11 supported as documentation said?

mfussenegger commented 10 months ago

is java 11 supported as documentation said?

eclipse.jdt.ls itself requires at least java 17 You can use it to work on projects with a lower java source-/targetCompatibility but at least the gradle version needs to be compatible with java 17. At least until https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/2812 - I think after that it tries to detect a compatible version.