Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bAmrish opened this issue Sep 19, 2023 · 11 comments

Comments

@bAmrish
Copy link

bAmrish commented Sep 19, 2023

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
Copy link

brcolow commented Sep 27, 2023

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
Copy link

badloop commented Oct 5, 2023

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
Copy link

brcolow commented Oct 5, 2023

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

@LorenzoBettini
Copy link

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

@crizzy9
Copy link

crizzy9 commented Dec 20, 2023

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
Copy link

Mo0rBy commented Jan 18, 2024

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
Copy link

Using v21 got me working as well

@victorh1705
Copy link

victorh1705 commented Mar 28, 2024

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
Copy link

logrusx commented Apr 14, 2024

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
Copy link

jonathanabennett commented Sep 22, 2024

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
Copy link

logrusx commented Sep 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants