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

scala-cli can't fetch JavaFX related dependencies for ScalaFX #3168

Open
Dieken opened this issue Sep 12, 2024 · 6 comments
Open

scala-cli can't fetch JavaFX related dependencies for ScalaFX #3168

Dieken opened this issue Sep 12, 2024 · 6 comments
Labels
bug Something isn't working coursier Issues tied with coursier integration. javafx Issues tied with JavaFX and ScalaFX

Comments

@Dieken
Copy link

Dieken commented Sep 12, 2024

Version(s)

$ scala-cli version
Scala CLI version: 1.5.0
Scala version (default): 3.5.0

$ java -version
openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode)

Describe the bug

$ cat scalafx.scala 
//> using scala 3.5.0
//> using toolkit 0.5.0
//> using dep "org.scalafx::scalafx:22.0.0-R33"

import scalafx.application.JFXApp3
import scalafx.geometry.Insets
import scalafx.scene.Scene
import scalafx.scene.effect.DropShadow
import scalafx.scene.layout.HBox
import scalafx.scene.paint.*
import scalafx.scene.paint.Color.*
import scalafx.scene.text.Text

import scala.language.implicitConversions

object ScalaFXHelloWorld extends JFXApp3 :

  override def start(): Unit =

    stage = new JFXApp3.PrimaryStage :
      //    initStyle(StageStyle.Unified)
      title = "ScalaFX Hello World"
      scene = new Scene :
        fill = Color.rgb(38, 38, 38)
        content = new HBox :
          padding = Insets(50, 80, 50, 80)
          children = Seq(
            new Text :
              text = "Scala"
              style = "-fx-font: normal bold 100pt sans-serif"
              fill = new LinearGradient(endX = 0, stops = Stops(Red, DarkRed))
            ,
            new Text :
              text = "FX"
              style = "-fx-font: italic bold 100pt sans-serif"
              fill = new LinearGradient(endX = 0, stops = Stops(White, DarkGray))
              effect = new DropShadow :
                color = DarkGray
                radius = 15
                spread = 0.25
          )

To Reproduce

$ scala-cli scalafx.scala
[error] ./scalafx.scala:2:19
[error] Error fetching artifacts:
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-controls/22/javafx-controls-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-controls/22/javafx-controls-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-media/22/javafx-media-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-media/22/javafx-media-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-graphics/22/javafx-graphics-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-graphics/22/javafx-graphics-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-swing/22/javafx-swing-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-swing/22/javafx-swing-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-fxml/22/javafx-fxml-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-fxml/22/javafx-fxml-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-base/22/javafx-base-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-base/22/javafx-base-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-web/22/javafx-web-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-web/22/javafx-web-22-${javafx.platform}.jar
[error] //> using toolkit 0.5.0
[error]                   ^^^^^
[error] ./scalafx.scala:3:16
[error] Error fetching artifacts:
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-controls/22/javafx-controls-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-controls/22/javafx-controls-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-media/22/javafx-media-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-media/22/javafx-media-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-graphics/22/javafx-graphics-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-graphics/22/javafx-graphics-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-swing/22/javafx-swing-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-swing/22/javafx-swing-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-fxml/22/javafx-fxml-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-fxml/22/javafx-fxml-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-base/22/javafx-base-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-base/22/javafx-base-22-${javafx.platform}.jar
[error] https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-web/22/javafx-web-22-${javafx.platform}.jar: not found: https://maven-central-asia.storage-download.googleapis.com/maven2/org/openjfx/javafx-web/22/javafx-web-22-${javafx.platform}.jar
[error] //> using dep "org.scalafx::scalafx:22.0.0-R33"
[error]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expected behaviour

It should runs successfully. The SBT project https://github.com/scalafx/scalafx-hello-world works for scalafx-21.0.0-R32 and scalafx-22.0.0-R33.

@Dieken Dieken added the bug Something isn't working label Sep 12, 2024
@Dieken
Copy link
Author

Dieken commented Sep 12, 2024

Scala-cli nightly works, so close this issue.

$ scala-cli --cli-version nightly version
Scala CLI version: 1.5.0-43-gc1d70b43f-SNAPSHOT
Scala version (default): 3.5.0

$ scala-cli --cli-version nightly scalafx.scala
Sep 12, 2024 8:14:18 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @1e7ba8d9'
Sep 12, 2024 8:14:24 PM com.sun.glass.ui.mac.MacApplication lambda$waitForReactivation$6
WARNING: Timeout while waiting for app reactivation

@Dieken Dieken closed this as completed Sep 12, 2024
@Dieken Dieken reopened this Sep 12, 2024
@Dieken
Copy link
Author

Dieken commented Sep 12, 2024

Reopen, just find scala-cli --cli-version 1.5.0 scalafx.scala works, but scala-cli-1.5.0 scala-cli scalafx.scala doesn't work.

My scala-cli-1.5.0 is installed by Coursier CLI on macOS 14.5.

@Gedochao Gedochao added the requires scoping Issue requires a spike to revalidate it and assign an up-to date scope for its requirements. label Sep 16, 2024
@Gedochao
Copy link
Contributor

Reopen, just find scala-cli --cli-version 1.5.0 scalafx.scala works, but scala-cli-1.5.0 scala-cli scalafx.scala doesn't work.

My scala-cli-1.5.0 is installed by Coursier CLI on macOS 14.5.

--cli-version 1.5.0 would change the launcher type to JVM, which somehow fixes that. This seems to be broken for native launchers only, for some reason.
Either way, it seems the javafx.platform pom property isn't being set, which is preventing coursier from downloading the dependencies...
We likely should either set this ourselves, or enable for the user to set it via a flag/classifier/directive.
Related:

@Gedochao Gedochao added coursier Issues tied with coursier integration. and removed requires scoping Issue requires a spike to revalidate it and assign an up-to date scope for its requirements. labels Sep 16, 2024
@tgodzik
Copy link
Member

tgodzik commented Sep 17, 2024

I think this happens here https://github.com/coursier/coursier/blob/af465c453fe7519fdf3b813b919f1970e9a98d4c/modules/core/shared/src/main/scala/coursier/core/Resolution.scala#L516

but I can't find exactly why it wouldn't happen for native image.

@tgodzik
Copy link
Member

tgodzik commented Sep 17, 2024

This seems to fix things for me:

https://github.com/VirtusLab/scala-cli/compare/main...tgodzik:scala-cli:add-props?expand=1

So the workaround would be to forward any properties to resolution params and have users add them manually. But I can't figure out why it's not happening out of the box. We could even have our own pom-property for this specific use.

@Dieken
Copy link
Author

Dieken commented Sep 18, 2024

I guess inserting this clause somewhere will fix it:

r.withOsInfo(
          coursier.core.Activation.Os.fromProperties(sys.props.toMap),
        )

See sbt/sbt#6564 (comment)

As the description above said, the SBT project https://github.com/scalafx/scalafx-hello-world just works without any customized properties.

@Gedochao Gedochao added the javafx Issues tied with JavaFX and ScalaFX label Sep 19, 2024
@Gedochao Gedochao changed the title scala-cli can't fetch javafx related dependencies scala-cli can't fetch JavaFX related dependencies for ScalaFX Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working coursier Issues tied with coursier integration. javafx Issues tied with JavaFX and ScalaFX
Projects
None yet
Development

No branches or pull requests

3 participants