eclipse-jdtls / eclipse.jdt.ls

Java language server
1.8k stars 400 forks source link

Runtime JDK/JRE dependency on java 17? #2217

Closed puremourning closed 2 years ago

puremourning commented 2 years ago

Sorry if I missed it, but is the runtime requirement for jdt.ls written down somewhere?

It seems like it requires java 17 from a quick code inspection, whereas it previously only required java 11.

Is that right? Reason I ask is that adopt openjdk claims that 16 is the latest stable java. Anyway, would be useful to clarify what the runtime requirements are for jdt.ls.

(sorry, not an issue, but a question. I asked on mattermost, but no reply).

fbricon commented 2 years ago

Yes Java 17 as a minimum is now required to run, as m2e, a core jdt.ls dependency now requires Java 17 to run. However you can still compile projects back to Java 1.5

puremourning commented 2 years ago

OK thanks.

dave-kennedy commented 2 years ago

Yes Java 17 as a minimum is now required to run, as m2e, a core jdt.ls dependency now requires Java 17 to run. However you can still compile projects back to Java 1.5

Can you clarify the distinction between running and compiling? How do you use jdtls to compile? How do I use jdtls with a project that uses Java 8?

snjeza commented 2 years ago

How do you use jdtls to compile? How do I use jdtls with a project that uses Java 8?

What project are you using? Maven, Gradle, standard Eclipse?

dave-kennedy commented 2 years ago

I think I finally figured it out. The Java version used to run jdtls has to be >= 17, but the Java version used to compile the project can be configured separately. This is how it's done for nvim-jdtls:

local config = {
    cmd = {
        'java',
        '-Declipse.application=org.eclipse.jdt.ls.core.id1',
        '-Dosgi.bundles.defaultStartLevel=4',
        '-Declipse.product=org.eclipse.jdt.ls.core.product',
        '-Dlog.level=ALL',
        '-noverify',
        '-Xmx1G',
        '--add-modules=ALL-SYSTEM',
        '--add-opens', 'java.base/java.util=ALL-UNNAMED',
        '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
        '-jar', '/home/dave/.jdtls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar',
        '-configuration', '/home/dave/.jdtls/config_linux',
        '-data', '/home/dave/.jdtls/workspaces' .. project_name
    },
    settings = {
        java = {
            configuration = {
                runtimes = {
                    {
                        name = 'JavaSE-1.8',
                        path = '/home/dave/.sdkman/candidates/java/8.0.302-open/',
                    }
                }
            }
        }
    }
}

I'm not sure how to do it outside of nvim-jdtls.

snjeza commented 2 years ago

@dave-kennedy You may want to take a look at Project JDKs

dave-kennedy commented 2 years ago

@snjeza thanks, that is helpful. Can that be set alongside configuration.runtimes or does it need to be in gradle.properties?

snjeza commented 2 years ago

@dave-kennedy java.configuration.runtimes

dave-kennedy commented 2 years ago

For the record, this is what did the trick:

local config = {
    cmd = {
        '/home/dave/.sdkman/candidates/java/18.0.2.1-open/bin/java',
        '-Declipse.application=org.eclipse.jdt.ls.core.id1',
        '-Dosgi.bundles.defaultStartLevel=4',
        '-Declipse.product=org.eclipse.jdt.ls.core.product',
        '-Dlog.level=ALL',
        '-noverify',
        '-Xmx1G',
        '--add-modules=ALL-SYSTEM',
        '--add-opens', 'java.base/java.util=ALL-UNNAMED',
        '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
        '-jar', '/home/dave/.jdtls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar',
        '-configuration', '/home/dave/.jdtls/config_linux',
        '-data', '/home/dave/.jdtls/workspaces/' .. project_name
    },
    settings = {
        java = {
            configuration = {
                runtimes = {
                    {
                        name = 'JavaSE-1.8',
                        path = '/home/dave/.sdkman/candidates/java/8.0.302-open/',
                        default = true
                    },
                    {
                        name = 'JavaSE-18',
                        path = '/home/dave/.sdkman/candidates/java/18.0.2.1-open/'
                    }
                }
            },
            import = {
                gradle = {
                    home = '/home/dave/.sdkman/candidates/java/8.0.302-open/'
                }
            }
        }
    }
}

Except now none of my libs aren importing but that's another issue.