You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# # Wrote /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/v170/helloFromTestScope, run it with
49
+
# ./helloFromTestScope
50
+
./helloFromTestScope
51
+
# Hello from the test scope!
52
+
```
53
+
54
+
Keep in mind that the test and main scopes are still separate compilation units, where the test scope depends on the main scope (while the reverse isn't true).
55
+
56
+
Added by [@Gedochao](https://github.com/Gedochao) in [#3502](https://github.com/VirtusLab/scala-cli/pull/3502) and [#3519](https://github.com/VirtusLab/scala-cli/pull/3519)
57
+
58
+
### Detect objects with main class in scripts
59
+
60
+
Scala CLI now detects objects with a main method in scripts and runs them by default.
61
+
62
+
```scala title=scriptMainObject.sc
63
+
object Main {
64
+
def main(args: Array[String]): Unit = println("Hello")
65
+
}
66
+
```
67
+
68
+
Do note that, this is chiefly a convenience feature for migration of old scripts, using the old, legacy `scala` runner.
69
+
70
+
If any top-level code is present alongside an object with a main method, the top-level code will be run instead and a warning printed.
71
+
72
+
```scala title=scriptWithMainObjectAndTopLevel.sc
73
+
object Main {
74
+
def main(args: Array[String]): Unit = println("Hello")
75
+
}
76
+
println("Top level code says hello")
77
+
```
78
+
79
+
```bash
80
+
scala-cli run scriptWithMainObjectAndTopLevel.sc
81
+
# [warn] Script contains objects with main methods and top-level statements, only the latter will be run.
82
+
# Compiling project (Scala 3.6.3, JVM (23))
83
+
# Compiled project (Scala 3.6.3, JVM (23))
84
+
# Top level code says hello
85
+
```
86
+
87
+
Additionally, cases where multiple main methods are present in the same script are not supported, inidicated by a warning.
88
+
89
+
```scala title=scriptWithMultipleMainObjects.sc
90
+
object Main {
91
+
def main(args: Array[String]): Unit = println("Hello1")
92
+
}
93
+
94
+
object Main2 {
95
+
def main(args: Array[String]): Unit = println("Hello2")
96
+
}
97
+
```
98
+
99
+
Note that no output is printed in this example:
100
+
101
+
```bash
102
+
scala-cli run scriptWithMultipleMainObjects.sc
103
+
# [warn] Only a single main is allowed within scripts. Multiple main classes were found in the script: Main, Main2
104
+
# Compiling project (Scala 3.6.3, JVM (23))
105
+
# Compiled project (Scala 3.6.3, JVM (23))
106
+
```
107
+
108
+
Finally, main methods defined in this way cannot be chosen via the `--main-class` command line option directive,
109
+
and neither will they be printed by the `--list-main-methods` flag.
110
+
111
+
Added by [@tgodzik](https://github.com/tgodzik) in [#3479](https://github.com/VirtusLab/scala-cli/pull/3479)
112
+
113
+
### Support for Scala Native 0.5.7
114
+
This Scala CLI version switches the default Scala Native version to 0.5.7.
115
+
116
+
```bash
117
+
scala-cli -e 'println("Hello from Scala Native 0.5.7!")' --native
# [info] Multithreading was not explicitly enabled - initial class loading has not detected any usage of system threads. Multithreading support will be disabled to improve performance.
Added in [#3527](https://github.com/VirtusLab/scala-cli/pull/3527)
140
+
141
+
### Features
142
+
* improvement: Detect objects with main class in scripts by [@tgodzik](https://github.com/tgodzik) in [#3479](https://github.com/VirtusLab/scala-cli/pull/3479)
143
+
* Add support for running a main method from the test scope by [@Gedochao](https://github.com/Gedochao) in [#3502](https://github.com/VirtusLab/scala-cli/pull/3502)
144
+
* Support the `--test` flag with the `package` sub-command by [@Gedochao](https://github.com/Gedochao) in [#3519](https://github.com/VirtusLab/scala-cli/pull/3519)
145
+
146
+
### Fixes
147
+
* Improve handling for parallel Scala CLI runs by [@Gedochao](https://github.com/Gedochao) in [#3399](https://github.com/VirtusLab/scala-cli/pull/3399)
148
+
* fix: Don't compile docs if there is no need by [@ghostbuster91](https://github.com/ghostbuster91) in [#3503](https://github.com/VirtusLab/scala-cli/pull/3503)
149
+
* fix: correctly report error position on unknown directive without values by [@kasiaMarek](https://github.com/kasiaMarek) in [#3518](https://github.com/VirtusLab/scala-cli/pull/3518)
150
+
151
+
### Internal and build changes
152
+
* fix for #3510 by [@philwalk](https://github.com/philwalk) in [#3513](https://github.com/VirtusLab/scala-cli/pull/3513)
153
+
* Fall back to the `cs` command on `PATH` in the `mill` script by [@Gedochao](https://github.com/Gedochao) in [#3517](https://github.com/VirtusLab/scala-cli/pull/3517)
154
+
155
+
### Documentation changes
156
+
* Curl install launcher in your repo by [@joan38](https://github.com/joan38) in [#3532](https://github.com/VirtusLab/scala-cli/pull/3532)
157
+
158
+
### Updates
159
+
* Update scala-cli.sh launcher for 1.6.2 by [@github-actions](https://github.com/github-actions) in [#3495](https://github.com/VirtusLab/scala-cli/pull/3495)
160
+
* Update metaconfig-typesafe-config to 0.15.0 by [@scala-steward](https://github.com/scala-steward) in [#3497](https://github.com/VirtusLab/scala-cli/pull/3497)
161
+
* Update bloop-config_2.13 to 2.3.2 by [@scala-steward](https://github.com/scala-steward) in [#3496](https://github.com/VirtusLab/scala-cli/pull/3496)
162
+
* Update semanticdb-shared_2.13 to 4.13.0 by [@scala-steward](https://github.com/scala-steward) in [#3500](https://github.com/VirtusLab/scala-cli/pull/3500)
163
+
* Update ammonite to 3.0.2 by [@scala-steward](https://github.com/scala-steward) in [#3504](https://github.com/VirtusLab/scala-cli/pull/3504)
164
+
* Update semanticdb-shared_2.13 to 4.13.1.1 by [@scala-steward](https://github.com/scala-steward) in [#3508](https://github.com/VirtusLab/scala-cli/pull/3508)
165
+
* Update scalafix-interfaces to 0.14.1 by [@scala-steward](https://github.com/scala-steward) in [#3511](https://github.com/VirtusLab/scala-cli/pull/3511)
166
+
* Update semanticdb-shared_2.13 to 4.13.2 by [@scala-steward](https://github.com/scala-steward) in [#3515](https://github.com/VirtusLab/scala-cli/pull/3515)
167
+
* Update scalafix-interfaces to 0.14.2 by [@scala-steward](https://github.com/scala-steward) in [#3514](https://github.com/VirtusLab/scala-cli/pull/3514)
168
+
* Update slf4j-nop to 2.0.17 by [@scala-steward](https://github.com/scala-steward) in [#3520](https://github.com/VirtusLab/scala-cli/pull/3520)
169
+
* Bump Scala 3 Next RC to 3.6.4-RC2 by [@Gedochao](https://github.com/Gedochao) in [#3525](https://github.com/VirtusLab/scala-cli/pull/3525)
170
+
* Update Scala Native to 0.5.7 by [@scala-steward](https://github.com/scala-steward) in [#3527](https://github.com/VirtusLab/scala-cli/pull/3527)
171
+
* Bump `scala-packager` to 0.1.32 & linux CI runners to `ubuntu-24.04` by [@Gedochao](https://github.com/Gedochao) in [#3528](https://github.com/VirtusLab/scala-cli/pull/3528)
172
+
* Update `scalafmt` to 3.9.1 by [@Gedochao](https://github.com/Gedochao) in [#3521](https://github.com/VirtusLab/scala-cli/pull/3521)
173
+
* Bump `scalafmt` to 3.9.2 by [@Gedochao](https://github.com/Gedochao) in [#3533](https://github.com/VirtusLab/scala-cli/pull/3533)
174
+
* Bump gifs tests Ubuntu Docker image to `ubuntu:24.04` by [@Gedochao](https://github.com/Gedochao) in [#3534](https://github.com/VirtusLab/scala-cli/pull/3534)
175
+
* Update sbt, scripted-plugin to 1.10.9 by [@scala-steward](https://github.com/scala-steward) in [#3537](https://github.com/VirtusLab/scala-cli/pull/3537)
176
+
* Bump Linux ARM64 Docker image to `ubuntu:24.04` by [@Gedochao](https://github.com/Gedochao) in [#3535](https://github.com/VirtusLab/scala-cli/pull/3535)
0 commit comments