java-language-server icon indicating copy to clipboard operation
java-language-server copied to clipboard

Getting "invalid target release: 18" when installing java lsp via Mason in Neovim

Open bAmrish opened this issue 2 years ago • 13 comments

I am trying to setup my neovim instance with Java LSP. I am using Mason to help install the LSPs. When installing java lsp I am getting following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) 
on project javac-services: Fatal error compiling: error: invalid target release: 18 -> [Help 1]

I have tried setting JAVA_HOME to both 11 and 1.8, but I get the same error.

Here is the full log of the error

 Cloning git repository "https://github.com/georgewfraser/java-language-server.git"…
        Cloning into '.'...
        From https://github.com/georgewfraser/java-language-server
         * tag               v0.2.39    -> FETCH_HEAD
        + ./scripts/link_mac.sh
        + mvn package -DskipTests
        [INFO] Scanning for projects...
        [INFO] 
        [INFO] ---------------------< org.javacs:javac-services >----------------------
        [INFO] Building javac-services 0.1-SNAPSHOT
        [INFO]   from pom.xml
        [INFO] --------------------------------[ jar ]---------------------------------
        [INFO] 
        [INFO] --- resources:3.3.1:resources (default-resources) @ javac-services ---
        [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
        [INFO] skip non existing resourceDirectory /Users/amrish/.local/share/nvim/mason/staging/java-language-server/src/main/resources
        [INFO] 
        [INFO] --- compiler:3.8.0:compile (default-compile) @ javac-services ---
        [INFO] Changes detected - recompiling the module!
        [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
        [INFO] Compiling 357 source files to /Users/amrish/.local/share/nvim/mason/staging/java-language-server/target/classes
        [INFO] ------------------------------------------------------------------------
        [INFO] BUILD FAILURE
        [INFO] ------------------------------------------------------------------------
        [INFO] Total time:  0.384 s
        [INFO] Finished at: 2023-09-19T12:01:08+05:30
        [INFO] ------------------------------------------------------------------------
        [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project javac-services: Fatal error compiling: error: invalid target release: 18 -> [Help 1]
        [ERROR] 
        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
        [ERROR] 
        [ERROR] For more information about the errors and possible solutions, please read the following articles:
        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
        spawn: bash failed with exit code 1 and signal 0. 

Please let me know how to fix the error or if you need any more information.

bAmrish avatar Sep 19 '23 06:09 bAmrish

Looks like you need to set JAVA_HOME to be at least Java 18 (not 11 or 1.8 (which is version 8, not 18)).

brcolow avatar Sep 27 '23 22:09 brcolow

How does this make sense? I'm running into the same issue setting up my environment. I'm not configuring Java 18 because its not LTS, and everything we are writing is written using Java 17. Is there a way to install a previous version of the language server that uses 17 instead? Surely everyone who wants to write Java and use the java-language-server can't be expected to use whatever version the language server specifies...

Edit: ...and Java 18 isn't even an option in the standard Arch repos.

badloop avatar Oct 05 '23 13:10 badloop

I was just trying to be of assistance. Java 21 is LTS and is released now.

brcolow avatar Oct 05 '23 22:10 brcolow

@badloop Actually, you can use Java 21 (LTS) which will satisfy the Java 18 requirement. Of course, the documentation should be updated to require at least Java 18 (see https://github.com/georgewfraser/java-language-server/pull/271).

LorenzoBettini avatar Oct 11 '23 10:10 LorenzoBettini

Hi, is there any updates on this? I cannot update my java version since all our code is incompatible with Java 18. Is there anyway to make it work with Java 11?

crizzy9 avatar Dec 20 '23 07:12 crizzy9

This was exactly the issue I came across and updating to v21 worked, thank you! I use the sdkman tool for easily managing java versions, here it is if you're curious.

Mo0rBy avatar Jan 18 '24 13:01 Mo0rBy

Using v21 got me working as well

exosyphon avatar Mar 06 '24 16:03 exosyphon

I understand what he means. He doesn’t want the JAVA_HOME to be set to the newer version, but rather to the version he uses in his projects, to avoid any kind of incompatibility.

So, I think the point is how to set different Java versions, one for this project and another for the Java Language Server, so it won’t lead to an error.

Since it's a setup problem and not a issue with the lsp, I think this issue can be closed.

victorh1705 avatar Mar 28 '24 13:03 victorh1705

Java 18 is an odd choice. I just manually changed it to 17 in pom.xml and it compiled just fine. Please change that to Java 17. There's still plenty of software that doesn't run on Java 21 and I don't see a way to use Java 21 only for java-language-server and 17 for the rest of my workspace.

logrusx avatar Apr 14 '24 16:04 logrusx

Java 18 is an odd choice. I just manually changed it to 17 in pom.xml and it compiled just fine. Please change that to Java 17. There's still plenty of software that doesn't run on Java 21 and I don't see a way to use Java 21 only for java-language-server and 17 for the rest of my workspace.

How did you change this? Would you mind giving me the step by step to change it myself? Specifically, where should I download the repo to so that Mason can find it?

jonathanabennett avatar Sep 22 '24 09:09 jonathanabennett

@jonathanabennett , I ended up not using this lsp, I don't remember for what reason. I think I modified the pom file outside of mason, just to check if it'll manually compile.

The changes necessary in pom.xml which should be at the top level are:

<properties> <java.version>18</java.version> </properties> to <properties> <java.version>17</java.version> </properties>

Note I'm taking this from a different pom just for illustration, if there are other tags inside properties don't touch them. Just change the java.version contents.

This most probably is how I compiled it. But I don't think I ever installed it through mason. I guess you can specify a plugin path in lazy.nvim or plug or packer or you could even manually install it, but you need to check the documentation for how to do that.

Instead I'd recommend settling for another lsp.

logrusx avatar Sep 22 '24 13:09 logrusx

The project apparently compiles just fine with Java 11+, after manually editing pom.xml. (Which, as far as I know, cannot be done easily in Mason).

diff --git a/pom.xml b/pom.xml
index a448b270..e1e456bc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -116,8 +116,8 @@
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.8.0</version>
                 <configuration>
-                    <source>18</source>
-                    <target>18</target>
+                    <source>11</source>
+                    <target>11</target>
                     <compilerArgs>
                         <arg>--add-exports</arg>
                         <arg>jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>

If there's no reason to force Java18, the pom.xml should be set to at least 17 LTS, which is still very widely used.

EricDuminil avatar May 06 '25 18:05 EricDuminil

The project apparently compiles just fine with Java 11+, after manually editing pom.xml. (Which, as far as I know, cannot be done easily in Mason).

It's been over an year I first posted in this issue and apparently I first fiddled with Neovim, so I now know you don't need to use Mason. You can use it for other stuff and manually setup the language server in lsp-config's configuration. But honestly, I wouldn't attempt that, because I don't see anything in this language server that's worth doing it. It's just another language server.

If there's no reason to force Java18, the pom.xml should be set to at least 17 LTS, which is still very widely used.

There's absolutely no reason. I now see I made a good decision not to waste my time on this and I guess what leads people here is lack of understanding the matter and the link on nvim-lspconfig's site.

Go watch TJ DeVries Advent of Neovim TJ DeVries series to understand how program lua and how lazy.nvim and lsp work. Go Watch MrJakob's series on how to setup Neovim from scratch. Then fiddle around with nvim-jdtls, nvim-java and similar and you'll get the hang of it.

This repo is dead and you're not likely to get anything from it.

logrusx avatar May 06 '25 19:05 logrusx