Skip to content

compileOnlyApi with Gradle causes Java Language Server to not find imports #2904

@Kas-tle

Description

@Kas-tle

When using a Gradle project, the Java Language Server does not seem to play nice when compileOnlyApi is used as a dependency type. Multiple errors occur as to the Java Language Server, the dependency is not resolved despite Gradle being able to build the project without issues. The same seems to occur for compileOnly.

See https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph for definitions.

The following is an example of a repo with the issue: https://github.com/GeyserMC/Floodgate

Environment
  • Operating System: Ubuntu 20.04.4 LTS
  • JDK version: 1.8
  • Visual Studio Code version: 1.74.3
  • Java extension version: 1.14.0
Steps To Reproduce
  1. Clone a repo with the issue (e.g. https://github.com/GeyserMC/Floodgate)
git clone https://github.com/GeyserMC/Floodgate
  1. Open the repo in VSCode and attempt to build with the Java Language Server
  2. Observe that there are unresolved imports in the database module.
  3. In one of the submodules for database, for example, database/mongo/build.gradle.kts, change the dependency type from provided (which is defined here as an alias for compileOnlyApi) to api.
val mongoClientVersion = "4.4.1"

dependencies {
    api(projects.core)
    // provided(projects.core)
    implementation("org.mongodb", "mongodb-driver-sync" , mongoClientVersion)
}

description = "The Floodgate database extension for MongoDB"

relocate("com.mongodb")
relocate("org.bson")
  1. Clean the Java Language Server Workspace from the command palette, and select Load & Delete when prompted to relaunch VSCode.
  2. After allowing the project to build, observe that the submodule database/mongo no longer contains missing dependencies.

Please attach a sample project reproducing the error: https://github.com/GeyserMC/Floodgate
Please attach logs: https://gist.github.com/Kas-tle/38ac89a54417f5b248f1a5fad3d28268

Current Result

Gradle projects with dependencies marked compileOnly/compileOnlyApi incorrectly show missing imports as the Java Language Server fails to resolve the dependencies.

Expected Result

The Java Language Server can correctly resolve compileOnly/compileOnlyApi dependencies.

Additional Informations

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions