Wrong classpath with Gradle `compileOnly` like instructions

Offen
#3,934 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
java, spring-boot, vscode

Rechercherichtung

Reproduziere das Projekt mit der gezeigten compileOnly-Abhängigkeit und vergleiche ./gradlew bootRun mit der Java-Startkonfiguration in .vscode/launch.json. Verfolge den für den VS Code-Start und die Testläufe zusammengestellten Klassenpfad; abgeschlossen bedeutet, dass compileOnly-Abhängigkeiten für die Kompilierung verfügbar bleiben, aber zur Laufzeit fehlen, entsprechend dem Verhalten von Gradle.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

upstream

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.

Vorherrschende Sprache
TypeScript
Sterne
2.3k
Forks
547
Ø Merge
20 Std. 1 Min.
Gemergte PRs (30 T.)
11

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus redhat-developer/vscode-java

Alle Issues in redhat-developer/vscode-java

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.