scala-cli
scala-cli copied to clipboard
scala-cli can't fetch JavaFX related dependencies for ScalaFX
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.
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
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.
Reopen, just find
scala-cli --cli-version 1.5.0 scalafx.scalaworks, but scala-cli-1.5.0scala-cli scalafx.scaladoesn'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:
- https://github.com/coursier/coursier/issues/2731
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.
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.
I guess inserting this clause somewhere will fix it:
r.withOsInfo(
coursier.core.Activation.Os.fromProperties(sys.props.toMap),
)
See https://github.com/sbt/sbt/issues/6564#issuecomment-908756816
As the description above said, the SBT project https://github.com/scalafx/scalafx-hello-world just works without any customized properties.