Skip to content

Print out the full Java version #2975

Open
@naferx

Description

@naferx

Is your feature request related to a problem? Please describe.

When executing a Scala script, scala-cli reports the Scala and Java version used.

$ echo 'println("hello world")' | scala-cli -
Compiling project (Scala 3.4.2, JVM (17))
Compiled project (Scala 3.4.2, JVM (17))
hello world

As noted, for Scala it shows the $MAJOR.$MINOR.$SECURITY version scheme but for Java it only prints out the $MAJOR part.

I'd like to know the full Java version used by scala-cli when not providing it via directives like //> using jvm 21.0.2 or command option --jvm 21.0.2. i.e

$ echo 'println("hello world")' | scala-cli --jvm 21.0.2 -
Compiling project (Scala 3.4.2, JVM (21.0.2))
Compiled project (Scala 3.4.2, JVM (21.0.2))
hello world

I have two reasons for this feature request:

  1. Debugging purposes, in case that by manual installation or using tools such as sdkman a machine has two similar Java versions
    x.y1.z1 and x.y2.z2 where x is the same in both installations.

  2. For consistency because the other platforms; Scala, Javascript and Scala-Native do report the full version since
    9d47089 (Merge pull request Bump Scala Native to 0.4.16 & log platform version #2465 from Gedochao/maintenance/scala-native-improvements, 2023-10-17)

Describe the solution you'd like
When running a script, it reports the full Java version being used

i.e

$ echo 'println("hello world")' | scala-cli -
Compiling project (Scala 3.4.2, JVM (17.0.11))
Compiled project (Scala 3.4.2, JVM (17.0.11))
hello world

Describe alternatives you've considered
If this feature request is not incorporated, and one would like to know the Java version, it would be necessary to inspect the Java version before hand via typing java --version

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

Additional context

After having a preliminary code revision, it seems like the change can be introduced in scala.build.options.BuildOptions#projectParams

Additionally, as stated in https://openjdk.org/jeps/223. There is a set of system properties that can be used to extract the version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    UXenhancementNew feature or requestjvmIssues tied to the JVM platform

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions