Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong classpath with Gradle compileOnly like instructions #3934

Open
pierrickrouxel opened this issue Jan 28, 2025 · 2 comments
Open

Wrong classpath with Gradle compileOnly like instructions #3934

pierrickrouxel opened this issue Jan 28, 2025 · 2 comments
Labels

Comments

@pierrickrouxel
Copy link

pierrickrouxel commented Jan 28, 2025

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.

@pierrickrouxel
Copy link
Author

Thank you for your answer. Hope this problem will be fixed soon. It totally breaks Spring with gradle in vscode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants