-
Notifications
You must be signed in to change notification settings - Fork 121
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
Add cookbook - Test your code with java 8 #179
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left more comments to @alexarchambault then to the code itself what shows how important creating of this cookbooks is (there is a chance that we do not handle JVM versions correctly)
website/docs/cookbooks/scala-jvm.md
Outdated
Passing `--jvm` to the `scala-cli` command and run your application with the specified java version. | ||
|
||
```scala-cli | ||
scala-cli Main.scala --jvm adopt:11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexarchambault would it be possible to specify just --jvm 11
that will default to adopt-11?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is possible to specify just --jvm 11
or --jvm 8
etc. AdoptOpenJDK is used by default.
Here is more details about resolving jvm - coursier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could default to Java 11. The default JVM id is currently defined here.
scala-cli Main.scala --jvm adopt:8 | ||
# In this case, it raises an error because the `Files.createTempFile` method is not available in java 8 | ||
# | ||
# Exception in thread main: java.lang.Exception: java.lang.NoSuchMethodError: java.nio.file.Files.writeString(Ljava/nio/file/Path;Ljava/lang/CharSequence;[Ljava/nio/file/OpenOption;)Ljava/nio/file/Path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexarchambault isn't it bad behaviour? Should code simply does not compile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I specially prepared a code snippet that shouldn't compile in jvm 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JVM switching only works well at runtime, and less so for compiling. When compiling, the JVM of Bloop is actually used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but there are flags (--target
if I am not mistaken) to force scala compiler to check if this will compile against given JVM. @prolativ can help here
Co-authored-by: Krzysztof Romanowski <romanowski.kr@gmail.com>
Co-authored-by: Alexandre Archambault <alexarchambault@users.noreply.github.com>
Co-authored-by: Krzysztof Romanowski <romanowski.kr@gmail.com>
No description provided.