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

External dependencies can't be found from Gradle subprojects

Open dradtke opened this issue 6 years ago • 7 comments

We have a repository that contains several subprojects, something like

.
├── build.gradle
├── gradlew
├── project1
│   ├── build.gradle
│   └── src
└── project2
    ├── build.gradle
    └── src

Because of this, it doesn't appear that the language server can resolve dependencies when working within project1 or project2.

I tried to work around this by manually creating .vscode/settings.json, even developing a small Bash script that generates it for me:

#!/bin/bash
DIR="$(dirname "${BASH_SOURCE[0]}")/.."

DEP_REGEX='^.+:.+:[0-9\.]+$'
DEPS=()

for project in project1 project2; do
  echo "Retrieving dependencies for ${project}..."
  for word in $("${DIR}/gradlew" "${project}:dependencies" 2>/dev/null); do
    if [[ "${word}" =~ ${DEP_REGEX} ]]; then
      DEPS+=("\"${word}\"")
    fi
  done
done

mkdir -p "${DIR}/.vscode"
echo "{\"java.externalDependencies\":[$(IFS=,; echo "${DEPS[*]}")]}" | jq . > "${DIR}/.vscode/settings.json"

echo "External dependencies saved to .vscode/settings.json"

Even with this in place, it doesn't seem to work. Any thoughts?

dradtke avatar Jun 07 '19 15:06 dradtke

Seem to be hitting the same issue when dealing with gradle subprojects. I have to deal with a large mono-repo in my work which puts me in the same structure listed in @dradtke comment above. Attempted to resolve these missing dependencies by explicitly adding them in .vscode/settings.json both as java.classPath with the fully resolved local path, or java.externalDependencies using the gradle format. Neither of these seem to work.

liamsreya avatar Jul 11 '19 10:07 liamsreya

disregard my comment, turns out my issue was different. See #104 .

liamsreya avatar Jul 11 '19 13:07 liamsreya

If you list all external dependencies in .vscode/settings.json under java.externalDependencies, java-language-server (JLS) should find them in your ~/.gradle directory. If this isn't working, please copy your Java output from VSCode:

Output

georgewfraser avatar Aug 24 '19 18:08 georgewfraser

I have a forked branch that adds simple Gradle support to the dependency inference algorithm. It's not great, since Gradle's tooling API doesn't seem to offer an easy way to do this (https://github.com/gradle/gradle/issues/4215), but it seems to work reasonably well for me.

dradtke avatar Sep 05 '19 18:09 dradtke

Forgot to add the link to my branch: https://github.com/georgewfraser/java-language-server/compare/master...dradtke:basic-gradle-support

dradtke avatar Sep 05 '19 18:09 dradtke