redhat-developer / redhat-developer/vscode-java

Importing package from non-transitively exposed dependency in Gradle project does not display error

Open
#3,739 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Gradle
Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

Gradle enables Java library authors to specify what dependencies should be transitively exposed to a consumer using the api or implementation configurations in the dependencies section of the library's build script. When a Gradle application project attempts to use a class from a transitive dependency of a library that has declared that dependency non-transitively exposed (using implementation), the gradle build command fails at the import declaration as expected, but this extension reports no errors in VS Code likely because it sees the dependency on the classpath and ignores its transitive visibility setting. This extension will also provide hinting and code completion for a non-transitively exposed library, which shouldn't be happening.

Environment
  • Operating System: macOS/Docker ARM64
  • JDK version: OpenJDK Runtime Environment Corretto-21.0.4.7.1
  • Visual Studio Code version: 1.91.1 (through code-server)
  • Java extension version: 1.33.0 (through OpenVSX)
Steps To Reproduce
  1. Download the reproduction project.
  2. Open Test.java in VS Code and observe no compilation errors reported by this language server extension.
  3. Run gradle build, which will fail, and observe the compilation errors due to Test.java attempting to access the class of a non-transitively exposed dependency (com.google.common.base.Preconditions in the example) of the alpaca-java library.

Reproduction project: workspace.zip
Logs: Log.txt (nothing out of the ordinary)

Current Result

VS Code shows no errors:
VS Code

Expected Result

IntelliJ does show errors:
IntelliJ

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached workspace.zip, open Test.java, and run gradle build to compare its compiler errors with the language server's diagnostics. Read the Gradle dependency setup and Log.txt, then trace dependency visibility handling so the inaccessible Guava import produces an error and does not receive hinting or completion.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, vscode
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.