Skip to content

v1.0.0-RC2

Compare
Choose a tag to compare
@lwronski lwronski released this 09 May 20:02
· 1067 commits to main since this release
a38c525

What's Changed

Exclude

To exclude specific source files or entire directories from a Scala CLI project, you can now use the //> using exclude directive in your project.scala file.
Alternatively, you can do the same from the command line with the --exclude option.

  • absolute path: /root/path/to/your/project/Main.scala
  • relative path: src/main/scala/Main.scala
  • glob pattern: *.sc

For example, to exclude all files in the example/scala directory, add the following directive to your project.scala file:

//> using exclude "example/scala"

Added by @lwronski in #2053.

Directives with a Test Scope equivalent

Some directives now have a test scope equivalent, such as using dep and its test scope counterpart using test.dep. This allows you to declare dependencies that are only used in tests outside of test-specific sources.

For example, you can declare a dependency on munit in your project.scala file like this:

//> using test.dep "org.scalameta::munit::0.7.29"

The dependency will only be available in test sources.

Here's a list of directives with a test scope equivalent with example values:

 //> using test.dep "org.scalameta::munit::0.7.29"
 //> using test.jar "path/to/jar"
 //> using test.javaOpt "-Dfoo=bar"
 //> using test.javacOpt "source", "1.8", "target", "1.8"
 //> using test.javaProp "foo1=bar1"
 //> using test.option "-Xfatal-warnings"
 //> using test.resourceDir "testResources"
 //> using test.toolkit "latest"

Added by @Gedochao in #2046

Changes to using-directives syntax

We've made several updates to simplify the using directives syntax in this release:

  • allowed omitting commas in lists of values.
  • disallowed multiline comments.
  • removed multiline strings.
  • removed require and @require syntax support.
  • allowed values without quotes.
  • removed @using.

For example, the following using directives are now valid without the need for commas and quotes:

//> using scala 3.2.2
//> using javacOpt -source 1.8 -target 1.8

Added by @tgodzik in #2076

Bootstrapped standalone fat JAR.

The Scala CLI launcher is available as a standalone fat JAR. You can download the stable version of the Scala CLI fat JAR from Maven and try it now:

cs launch org.virtuslab.scala-cli:cliBootstrapped:1.0.0-RC2 -M scala.cli.ScalaCli

Added by @romanowski in #2005.

Access the path of the script being run from its code

With the special scriptPath function, you can now easily access the path of the script being run from the script code itself.
Here's an example of how to use the scriptPath value:

#!/usr/bin/env -S scala-cli shebang

println(scriptPath)
$ chmod +x scripts/hello.sc
$ ./scripts/hello.sc
# ./scripts/hello.sc

Added by @lwronski in #1990

Explicit Handling of Paths in using-directives

The ${.} pattern in directive values can now be replaced by the parent directory of the file containing the directive. This makes it possible to generate coverage output files relative to the source file location, for example:

//> using options "-coverage-out:${.}"

Added by @lwronski in #2040

Fix deadlocks in Script Wrappers

We have resolved an issue that caused deadlocks when threads were run from the static initializer of the wrapper object
(#532 and #1933).
Based on the feedback from the community (Thanks @dacr), we found that encapsulating the script code
into a class wrapper fixes the issue. The wrapper is generated by the Scala CLI and is not visible to the user.

This change alters the behavior of scripts that use the @main annotation. The @main annotation is no longer supported in .sc files.

@main def main(args: String*): Unit = println("Hello")
$ scala-cli script.sc
# [warn]  Annotation @main in .sc scripts is not supported, use .scala format instead
# Compiling project (Scala 3.2.2, JVM)
# [error] ./script.sc:1:1
# [error] method main cannot be a main method since it cannot be accessed statically
# [error] @main def main(args: String*): Unit = println("Hello")
# [error] ^^^^^
# Error compiling project (Scala 3.2.2, JVM)
# Compilation failed

Fixed by @MaciejG604 in #2033

Other changes

Publishing changes

Fixes

Documentation changes

Build and internal changes

Updates and maintenance

Full Changelog: v1.0.0-RC1...v1.0.0-RC2