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

Lombok and jvm_args #28

Closed
jemag opened this issue Jan 12, 2021 · 4 comments
Closed

Lombok and jvm_args #28

jemag opened this issue Jan 12, 2021 · 4 comments

Comments

@jemag
Copy link

jemag commented Jan 12, 2021

I have been trying to make Lombok work with nvim-jdtls with no success.

Previously, I was using coc-java and would have the following setting in my coc-settings.json:

  "java.jdt.ls.vmargs": "-javaagent:/home/jemag/.config/nvim/dependencies/lombok.jar -Xbootclasspath/a:/home/jemag/.config/nvim/dependencies/lombok.jar",

This allowed me to use Lombok in my java projects.

Right now, I am unsure how to achieve the same behavior. I have attempted to put it through jvm_args in init_options in a couple of different ways (I am not the best with lua):

function start_jdt()
    print("starting jdt")
    require('jdtls').start_or_attach({
    cmd = {'java-lsp.sh'},
    init_options = {
      bundles = {"/home/jemag/dev/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar"},
      --jvm_args = {"-javaagent:/home/jemag/.config/nvim/dependencies/lombok.jar", "-Xbootclasspath/a:/home/jemag/.config/nvim/dependencies/lombok.jar"}
      --jvm_args = {"-javaagent:/home/jemag/.config/nvim/dependencies/lombok.jar -Xbootclasspath/a:/home/jemag/.config/nvim/dependencies/lombok.jar"}
      --jvm_args = {["javaagent"]="/home/jemag/.config/nvim/dependencies/lombok.jar", ["Xbootclasspath/a"]="/home/jemag/.config/nvim/dependencies/lombok.jar"}
      --jvm_args = {["java.jdt.ls.vmargs"]="-javaagent:/home/jemag/.config/nvim/dependencies/lombok.jar -Xbootclasspath/a:/home/jemag/.config/nvim/dependencies/lombok.jar"}
    },
    on_attach = function(client)
    on_attach_common(client)
    on_attach_java(client)
    end
    })

end;

local autocmds = {
	lsp = {
		{"FileType",     "java",   "lua start_jdt()"};
	};
}

But none of the commented jvm_args would work. I then tried to modify my java-lsp.sh by adding it there:

 #!/bin/bash
 # -Xbootclasspath/a "/home/jemag/.config/nvim/dependencies/lombok.jar" \

JAR="$HOME/dev/eclipse/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_*.jar"
export GRADLE_HOME=/usr/bin/gradle
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 \
  -Xms1g \
  -Xmx2G \
  -jar $(echo "$JAR") \
  -configuration "$HOME/dev/eclipse/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/config_linux" \
  -javaagent:/home/jemag/.config/nvim/dependencies/lombok.jar \
  -data "$HOME/dev/eclipse/workspace" \
  --add-modules=ALL-SYSTEM \
  --add-opens java.base/java.util=ALL-UNNAMED \
  --add-opens java.base/java.lang=ALL-UNNAMED

This also did not seem to work. Both methods resulted in me still getting Lombok errors in my projects.

I was wondering if you had any ideas how this could be achieved properly with nvim-jdtls?

@mfussenegger
Copy link
Owner

coc-java uses the java.jdt.ls.vmargs option to adjust the command that is used to start the language server. So your variant that adjusts the java-lsp.sh script should be correct.

You could try using coc-java again, then use ps aux | grep java to find the exact command coc-java uses to start the language server and then adapt the java-lsp.sh based on that.

eclipse.jdt.ls itself doesn't support the vmargs or jvm_args option. So setting any of those within init_options won't have any affect.

@jemag
Copy link
Author

jemag commented Jan 13, 2021

Thanks for the tips.

So apparently -javaagent must always come before the -jar flag, once I did that change in my java-lsp.sh file, it started working properly. So basically:

 #!/bin/bash

JAR="$HOME/dev/eclipse/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_*.jar"
export GRADLE_HOME=/usr/bin/gradle
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 \
  -Xms1g \
  -Xmx2G \
  -javaagent:/home/jemag/.config/nvim/dependencies/lombok.jar \
  -Xbootclasspath/a:/home/jemag/.config/nvim/dependencies/lombok.jar \
  -jar $(echo "$JAR") \
  -configuration "$HOME/dev/eclipse/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/config_linux" \
  -data "$HOME/dev/eclipse/workspace" \
  --add-modules=ALL-SYSTEM \
  --add-opens java.base/java.util=ALL-UNNAMED \
  --add-opens java.base/java.lang=ALL-UNNAMED

@guysherman
Copy link

Just adding some extra info on top of @jemag's post...
I was getting class def not found issues when the LSP was trying to load. (It couldn't find javax.annotation.processing.AbstractProcessor) I found it was the -Xbootclasspath argument, apparently you shouldn't need it for recent versions of java, according to the lombok docs on using Lombok with ECJ/JDT (I'm guessing Java 11 on). Removing it resolved my issue.

@davidsoles
Copy link

Just adding some extra info on top of @jemag's post... I was getting class def not found issues when the LSP was trying to load. (It couldn't find javax.annotation.processing.AbstractProcessor) I found it was the -Xbootclasspath argument, apparently you shouldn't need it for recent versions of java, according to the lombok docs on using Lombok with ECJ/JDT (I'm guessing Java 11 on). Removing it resolved my issue.

Thank you very much my friend. You solved my problem 🥇

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

4 participants