vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

IntelliSense provided by this extension no longer work when the workspace includes `build.gradle`

Open tschaffter opened this issue 2 years ago • 8 comments

My team is developing in an Nx monorepo with VS Code where apps and libraries are listed in the folder apps/ and libs. Some of our apps and libs are in Java. We installed the Extension Pack for Java, which include this extension (Language Support for Java(TM) by Red Hat). Java projects are built with either Maven or Gradle. In this context, this VS Code extension works great as language support for Java. For example, IntelliSense works properly in VS Code for Java files.

I observed that this extension breaks when placing the file build.gradle in the workspace root folder. By breaking, I mean that IntelliSense is no longer working. See this issue for more detailed information and logs. The issue is related to the presence of the file build.gradle as an empty file still breaks the language support. Having a workspace-level build.gradle is a standard for multi-project build.

The expected behavior is that this VS Code extension should work fine in the context of multi-project build with Gradle.

Environment
  • Operating System: linux x64 (Debian 11)
  • JDK version: 17.0.4
  • Visual Studio Code version: 1.71.2
  • Java extension version: 1.10.0
Steps To Reproduce
  1. Clone this repo: https://github.com/Sage-Bionetworks/challenge-registry.git
  2. Checkout the commit 4e63ff1e150337882b680f05bf25c81bffa0fdfc
  3. Follow the README to setup the project
  4. Open a .java file > IntelliSense does not work
  5. Delete the file build.gradle
  6. Repeat Steps 3
  7. Open a .java file > IntelliSense works

Detailed logs can be found here.

Current Result

IntelliSense does not work in Java files. For example, no tooltip is displayed in VS Code when hovering on an import statement.

Expected Result

IntelliSense should work in Java files.

Additional Informations
$ nx report


 >  NX   Report complete - copy this into the issue template

   Node : 16.17.0
   OS   : linux x64
   yarn : 3.2.2
   
   nx : 14.5.4
   @nrwl/angular : 14.5.4
   @nrwl/cypress : 14.5.4
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.5.4
   @nrwl/eslint-plugin-nx : 14.5.4
   @nrwl/express : Not Found
   @nrwl/jest : 14.5.4
   @nrwl/js : 14.5.4
   @nrwl/linter : 14.5.4
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 14.5.4
   @nrwl/nx-cloud : 14.3.0
   @nrwl/nx-plugin : 14.5.4
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.5.4
   @nrwl/web : 14.5.4
   @nrwl/workspace : 14.5.4
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:
         @nguniversal/express-engine: 14.2.0
         @nguniversal/builders: 14.2.0
         @nx-tools/nx-docker: 2.3.0
         @nxrocks/nx-spring-boot: 5.0.2
$ code --list-extensions --show-versions
Extensions installed on Dev Container: Challenge @ ssh://devcontainers-ssm:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

tschaffter avatar Sep 20 '22 00:09 tschaffter

Why not put the build.gradle under apps and meanwhile, add settings.gradle under apps to declare all your sub-modules?

jdneo avatar Sep 20 '22 08:09 jdneo

@tschaffter You can try the following:

$ cd challenge-registry
$ rm gradlew gradlew.bat

or

$ cd challenge-registry
$ cp -a libs/shared-java/challenge-util/gradle .

snjeza avatar Sep 20 '22 14:09 snjeza

Why not put the build.gradle under apps and meanwhile, add settings.gradle under apps to declare all your sub-modules?

I'm relatively new to Gradle so not sure how this would work. Related to that I saw that there is a property buildFile that can be specified in settings.json to specify the location of build.gradle. However, specifying the location of a build file seems deprecated.

@snjeza I'm not sure how these two suggestions could help. Also, the presence of either gradlew or gradlew.bat in the workspace root folder was a condition for the activation of the VS Code extension Spotless Gradle that I used until recently.

I found a satisfying workaround that eliminates my need of having build.gradle in the workspace folder (see https://github.com/Sage-Bionetworks/challenge-registry/pull/724). However, the issue remain that this language support extension may break for developers who work on projects that include a build.gradle in the workspace folder.

tschaffter avatar Sep 20 '22 16:09 tschaffter

@snjeza I'm not sure how these two suggestions could help. Also, the presence of either gradlew or gradlew.bat in the workspace root folder was a condition for the activation of the VS Code extension Spotless Gradle that I used until recently.

You have installed a gradle wrapper partially and Java LS crashes. You have the valid gradle wrapper in the libs/shared-java/challenge-util project. You should just copy it.

snjeza avatar Sep 20 '22 17:09 snjeza

Thanks @snjeza. I indeed forgot to commit the folder gradle in the commit I referenced earlier. However, I usually included this folder in my setup. To clarify, Java LS breaks with the following files in my workspace folder:

$ git status -u    
On branch test-gradle-setup
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        build.gradle
        gradle/wrapper/gradle-wrapper.jar
        gradle/wrapper/gradle-wrapper.properties
        gradlew
        gradlew.bat

nothing added to commit but untracked files present (use "git add" to track)

tschaffter avatar Sep 20 '22 17:09 tschaffter

@tschaffter You can skip the gradle importer using

"java.import.gradle.enabled": false,

snjeza avatar Sep 20 '22 19:09 snjeza

I'm relatively new to Gradle so not sure how this would work. Related to that I saw that there is a property buildFile that can be specified in settings.json to specify the location of build.gradle. However, specifying the location of a build file seems deprecated.

settings.json is used to persist VS Code's settings. AFAIK, we haven't expose any setting to specify the build.gradle location.

jdneo avatar Sep 23 '22 03:09 jdneo

Is there some workaround for this issue? My build.gradle is on root and src folder is on root too, this is a single "module" project and i prefer this way. With this configuration it's impossible to use intellisense in java files.

ZantsuRocks avatar May 09 '24 16:05 ZantsuRocks