quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.4k stars 2.57k forks source link

Adding the quarkus gradle plugin to sample javafx app breaks gradle depencency resolution #36820

Open MarceloRuiz opened 8 months ago

MarceloRuiz commented 8 months ago

Describe the bug

Just by applying the quarkus.io gradle plugin to a minimal (but working) JavaFX Application, causes broken dependency resolutions (Cannot choose between following variants) during task quarkusGenerateCode even though the platform and architecture are correctly detected.

Expected behavior

Applying the quarkus.io plugin should not break dependency resolution for a working project

Actual behavior

A configuration exception is thrown because quarkus cannot choose between variants of javafx libraries

Execution failed for task ':jfxapp:quarkusGenerateCode'.
> Could not resolve all files for configuration ':jfxapp:quarkusProdBaseRuntimeClasspathConfiguration'.
   > Could not resolve org.openjfx:javafx-controls:21.0.1.
     Required by:
         project :jfxapp
      > Cannot choose between the following variants of org.openjfx:javafx-controls:21.0.1:
          - linux-aarch64Runtime
          - linuxRuntime
          - mac-aarch64Runtime
          - macRuntime
          - runtime
          - winRuntime
        All of them match the consumer attributes:
          - Variant 'linux-aarch64Runtime' capability org.openjfx:javafx-controls:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'aarch64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'linux' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'linuxRuntime' capability org.openjfx:javafx-controls:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'linux' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'mac-aarch64Runtime' capability org.openjfx:javafx-controls:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'aarch64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'macos' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'macRuntime' capability org.openjfx:javafx-controls:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'macos' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'runtime' capability org.openjfx:javafx-controls:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'winRuntime' capability org.openjfx:javafx-controls:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'windows' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
   > Could not resolve org.openjfx:javafx-fxml:21.0.1.
     Required by:
         project :jfxapp
      > Cannot choose between the following variants of org.openjfx:javafx-fxml:21.0.1:
          - linux-aarch64Runtime
          - linuxRuntime
          - mac-aarch64Runtime
          - macRuntime
          - runtime
          - winRuntime
        All of them match the consumer attributes:
          - Variant 'linux-aarch64Runtime' capability org.openjfx:javafx-fxml:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'aarch64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'linux' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'linuxRuntime' capability org.openjfx:javafx-fxml:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'linux' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'mac-aarch64Runtime' capability org.openjfx:javafx-fxml:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'aarch64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'macos' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'macRuntime' capability org.openjfx:javafx-fxml:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'macos' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'runtime' capability org.openjfx:javafx-fxml:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'winRuntime' capability org.openjfx:javafx-fxml:21.0.1:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.native.architecture 'x86-64' but the consumer didn't ask for it
                  - Provides org.gradle.native.operatingSystem 'windows' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it

How to Reproduce?

simple-jfx.zip

Sample application attached.

Unzip, cd into simple-jfx dir and build with:

./gradew clean build

The app will build with no problem.

Edit the file simple-jfx/jfxapp/build.gradle.kts and remove // in from the plugin to apply it. Save the file and execute again:

./gradew clean build

and the exception will be thrown

Output of uname -a or ver

Linux 6.2.0-36-generic #37~22.04.1-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk 21 2023-09-19 / OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15) / OpenJDK 64-Bit Server VM GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)

Quarkus version or git rev

3.4.3

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 8.4

Additional information

No response

quarkus-bot[bot] commented 8 months ago

/cc @glefloch, @quarkusio/devtools

MarceloRuiz commented 8 months ago

This problem can be fixed with the following code:

configurations.matching {
    it.isCanBeResolved && it.name.toString().contains("quarkus")
}.configureEach {
    attributes {
        attribute(Usage.USAGE_ATTRIBUTE, objects.named<Usage>(Usage.JAVA_RUNTIME))
        attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named<OperatingSystemFamily>("linux"))
        attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named<MachineArchitecture>("x86-64"))
    }
}

But I feel this is a workaround only. Maybe someone with knowledge about quarkus can comment on this? Thanks

Eng-Fouad commented 6 months ago

This problem can be fixed with the following code:

configurations.matching {
    it.isCanBeResolved && it.name.toString().contains("quarkus")
}.configureEach {
    attributes {
        attribute(Usage.USAGE_ATTRIBUTE, objects.named<Usage>(Usage.JAVA_RUNTIME))
        attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named<OperatingSystemFamily>("linux"))
        attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named<MachineArchitecture>("x86-64"))
    }
}

But I feel this is a workaround only. Maybe someone with knowledge about quarkus can comment on this? Thanks

Alternatively:

configurations.matching {
    it.isCanBeResolved && it.name.contains("quarkus")
}.configureEach {
    val runtimeAttributes = configurations.runtimeClasspath.get().attributes
    runtimeAttributes.keySet().forEach { key ->
        @Suppress("UNCHECKED_CAST")
        attributes.attribute(key as Attribute<Any>, runtimeAttributes.getAttribute(key) as Any)
    }
}
maxandersen commented 6 months ago

Not sure what code You are referring to. If you make it a PR we can see and run the test suite and see if anything obvious breaks.

jskov-jyskebank-dk commented 4 months ago

This works for me using groovy and Gradle 8.6

configurations.matching {
  it.isCanBeResolved() && it.name.contains("quarkus")
}.configureEach {
  attributes {
    attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.class, Usage.JAVA_RUNTIME))
    attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, project.objects.named(OperatingSystemFamily.class, "linux"))
    attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, project.objects.named(MachineArchitecture.class, "x86-64"))
  }
}