eclipse-jdtls / eclipse.jdt.ls

Java language server
1.71k stars 384 forks source link

JDT LS doesn't use the project gradle wrapper #3149

Open saimanojk1 opened 2 months ago

saimanojk1 commented 2 months ago

Jdtls doesn't seem to use the gradle wrapper distribution from gradle properties and this is causing the build to fail. The following is my jdtls configuration for nvim-jdtls:

local status, jdtls = pcall(require, 'jdtls')
if not status then
  vim.notify('jdtls not found', vim.log.levels.WARN)
  return
end
local extendedClientCapabilities = jdtls.extendedClientCapabilities

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.protocol=true',
    '-Dlog.level=ALL',
    '-Xmx1g',
    '--add-modules=ALL-SYSTEM',
    '--add-opens',
    'java.base/java.util=ALL-UNNAMED',
    '--add-opens',
    'java.base/java.lang=ALL-UNNAMED',
    '-javaagent:' .. home .. '/.local/share/nvim/lombok.jar',
    '-jar',
    vim.fn.glob(home .. '/.local/share/nvim/mason/jdtls/plugins/org.eclipse.equinox.launcher_*.jar'),
    '-configuration',
    home .. '/.local/share/nvim/mason/jdtls/config_linux',
    '-data',
    workspace_dir,
  },
  root_dir = require('jdtls.setup').find_root { '.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle' },

  settings = {
    java = {
      signatureHelp = { enabled = true },
      extendedClientCapabilities = extendedClientCapabilities,
      maven = {
        downloadSources = true,
      },
      gradle = {
        wrapperEnabled = false,
      },
      referencesCodeLens = {
        enabled = true,
      },
      references = {
        includeDecompiledSources = true,
      },
      inlayHints = {
        parameterNames = {
          enabled = 'all', -- literals, all, none
        },
      },
      format = {
        enabled = false,
      },
      jdt = {
        ls = {
          java = { home = "/usr/lib/jvm/java-17-openjdk-amd64/",
          }
        }
      },
      configuration = {
        runtimes = {
          {
            name = "JavaSE-11",
            path = "/usr/lib/jvm/jdk-11/",
            default = true,
          },
          {
            name = "JavaSE-17",
            path = "/usr/lib/jvm/java-17-openjdk-amd64/",
          },
        },
      },
    },
  },

  init_options = {
    bundles = {},
  },
}
require('jdtls').start_or_attach(config)
fbricon commented 2 months ago

this should give you a hint:

gradle = {
        wrapperEnabled = false,
}
saimanojk1 commented 2 months ago

I have the same issue even if I toggle it true

saimanojk1 commented 2 months ago

Any updates on this please?

rgrunber commented 2 months ago

Can you try the following path instead of {java = { gradle = { wrapperEnabled = .. } } :

java = {
  import = {
    gradle = {
      wrapper = {
        enabled = true
      }
    }
  }
}
saimanojk1 commented 2 months ago

I tried that just yesterday actually, same issue

java = { 
     import = {
        gradle = {
          java = {
            home = "/usr/lib/jvm/jdk-11/",
          },
          wrapper = {
            enabled = true,
          },
          user = {
            home = "/local/.gradle/gradle.properties",
          },
        }
      },
}
jdneo commented 2 months ago

What if you leave the gradle user home empty?

See: https://docs.gradle.org/current/userguide/directory_layout.html#dir:gradle_user_home

saimanojk1 commented 2 months ago

Hi @jdneo doesn't seem to make a difference but good to learn about it. I removed that line.