georgewfraser / java-language-server

Java language server using the Java compiler API
MIT License
656 stars 130 forks source link

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

Open bAmrish opened 1 year ago

bAmrish commented 1 year ago

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.

brcolow commented 1 year ago

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)).

badloop commented 1 year ago

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.

brcolow commented 1 year ago

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

LorenzoBettini commented 1 year ago

@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).

crizzy9 commented 11 months ago

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?

Mo0rBy commented 10 months ago

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.

exosyphon commented 8 months ago

Using v21 got me working as well

victorh1705 commented 7 months ago

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.

logrusx commented 7 months ago

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.

jonathanabennett commented 1 month ago

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?

logrusx commented 1 month ago

@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:

`

18 ` to ` 17 ` 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.