redhat-developer / redhat-developer/vscode-java

Wrong classpath with Gradle `compileOnly` like instructions

Open
#3,934 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

We need to use the compileOnly in a gradle modules.
The expected behaviour is to have the dependency available at the compile time, but not at runtimes.

It's useful to create spring boot auto-configurations that load only if the dependency is present in the consumer module.

We have this declaration in a library:

dependencies {
  compileOnly 'org.springframework.boot:spring-boot-starter-security'
}

In the application module we have this declaration:

dependencies {
  implementation project(':libs:my-lib')
}

Running the following command, the project works as expected. The spring-boot-starter-security is not loaded.

./gradlew bootRun

But if we run the following configuration, the dependency is in classpath at runtime and the auto-configuration is applied at wrong.

{
  "configurations": [
    {
      "type": "java",
      "name": "Spring Boot-Application",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "mainClass": "com.mycompany.Application",
      "projectName": "application",
      "args": ""
    }
  ]
}

There is also dependency problems in test but I can't exactly explain what. There is some BeanDefinitionOverrideException that are not present running the ./gradlew test command.

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

Reproduce the project with the shown compileOnly dependency, comparing ./gradlew bootRun and the Java launch configuration in .vscode/launch.json. Trace the classpath assembled for the VS Code launch and test runs; done means compileOnly dependencies stay available for compilation but are absent at runtime, matching Gradle behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.