Skip to content

michelou/dotty-examples

Repository files navigation

Playing with Scala 3 on Windows

Dotty project This repository gathers Scala 3 code examples coming from various websites - mostly from the Dotty project - or written by ourself.
In particular it includes build scripts (Ant files, Bash scripts, batch files, Gradle scripts, Make scripts, Maven scripts) for experimenting with the Scala 3 language on a Windows machine.

This document is part of a series of topics related to Scala 3 on Windows:

Ada, Akka, C++, COBOL, Dafny, Dart, Deno, Docker, Erlang, Flix, Golang, GraalVM, Haskell, Kafka, Kotlin, LLVM, Modula-2, Node.js, Rust, Spark, Spring, TruffleSqueak, WiX Toolset and Zig are other topics we are continuously monitoring.

Project dependencies

This project depends on the following external software for the Microsoft Windows platform:

Optionally one may also install the following software:

Installation policy
When possible we install software from a Zip archive rather than via a Windows installer. In our case we defined C:\opt\ as the installation directory for optional software tools (in reference to the /opt/ directory on Unix).

For instance our development environment looks as follows (November 2024) 6:

C:\opt\apache-ant\                 ( 40 MB)
C:\opt\apache-maven\               ( 10 MB)
C:\opt\bazel\                      ( 47 MB)
C:\opt\cfr-0.152\                  (  2 MB)
C:\opt\Git\                        (367 MB)
C:\opt\gradle\                     (138 MB)
C:\opt\jacoco\                     ( 10 MB)
C:\opt\javafx-sdk-17.0.13\         (137 MB)
C:\opt\javafx-sdk-21.0.5\          (138 MB)
C:\opt\jdk-temurin-1.8.0u422-b05\  (189 MB)
C:\opt\jdk-temurin-17.0.13_11\     (301 MB)
C:\opt\jdk-temurin-21.0.5_11\      (326 MB)
C:\opt\jitwatch-1.4.9\             ( 36 MB)
C:\opt\mill\                       ( 67 MB)
C:\opt\msys64\                     (5.5 GB)
C:\opt\Python-3.11.1\              (299 MB)
C:\opt\sbt\                        (110 MB)
C:\opt\scala-2.13.15\              ( 24 MB)
C:\opt\scala-cli\                  ( 95 MB)
C:\opt\scala3-3.3.4\               ( 38 MB)
C:\opt\scala3-3.5.2\               (131 MB)
C:\opt\VSCode\                     (341 MB)

🔎 Git for Windows provides a Bash emulation used to run git.exe from the command line (as well as over 250 Unix commands like awk, diff, file, grep, more, mv, rmdir, sed and wc).

Directory structure

This project is organized as follows:

bin\*.bat
bin\cfr-0.152.zip
bin\3.0\{common.bat, scala.bat, scalac.bat, scaladoc.bat}
bin\3.1\{common.bat, scala.bat, scalac.bat, scaladoc.bat}
bin\3.2\{common.bat, scala.bat, scalac.bat, scaladoc.bat}
bin\dotty\
docs\
dotty\     (Git submodule)
examples\{README.md, dotty-example-project, ..}
maven-plugins\{README.md, scala-maven-plugin, etc.}
myexamples\{README.md, 00_AutoParamTupling, ..}
plugin-examples\{README.md, DivideZero, ..}
rockthejvm-examples\{README.md, Enums, ..}
semanticdb-examples\{README.md, hello, ..}
CONTRIBUTIONS.md
DEPS.md
README.md
RESOURCES.md
setenv.bat
UBUNTU_WSL.md

where

We also define a virtual drive – e.g. drive Y: – in our working environment in order to reduce/hide the real path of our project directory (see article "Windows command prompt limitation" from Microsoft Support).

🔎 Inside batch file setenv.bat we use the Windows external command subst to create virtual drives; for instance:

> subst Y: %USERPROFILE%\workspace\dotty-examples

In the next section we give a brief description of the batch files present in this project.

Batch/Bash commands

We distinguish different sets of batch/bash commands:

  1. setenv.bat – This batch command makes external tools such as maven.cmd, mill.bat and sbt.bat directly available from the command prompt (see section Project dependencies).

    > setenv help
    Usage: setenv { <option> | <subcommand> }
     
      Options:
        -bash       start Git bash shell instead of Windows command prompt
        -debug      print commands executed by this script
        -verbose    print progress messages
     
      Subcommands:
        help        print this help message
    
  2. Directory bin\ – This directory contains several utility batch files:

  3. Directory bin\3.0\ - This directory contains batch files to be copied to the bin\ directory of the Scala 3 installation for versions prior to 3.0.2 in order to use the scalac.bat, scaladoc.bat and scala.bat commands on Microsoft Windows.

    Starting with version 3.0.2 those batch files are included in the Scala 3 software distribution (see PR#13006, itself based on PR#5444).

     > dir /b c:\opt\scala3-3.3.4\bin
     common
     common.bat
     scala
     scala.bat
     scalac
     scalac.bat
     scaladoc
     scaladoc.bat
     
  1. File bin\dotty\build.bat - This batch command generates the Scala 3 software distribution from the Windows command prompt.

  2. File bin\dotty\build.sh - This bash command generates the Scala 3 software distribution from the Git Bash command prompt.

  3. File examples\*\build.bat - Finally each example can be built/run using the build.bat command.

    We favor build.bat for the following reasons:

    • It matches user commands executed from the Windows command prompt.
    • It provides subcommands for working with CFR, Scalafmt, JUnit and more.
    • Code examples are simple (mostly one single source file).
    • We don't need the sbt machinery (eg. library dependencies, sbt server).
     > build
     Usage: build { <option> | <subcommand> }
      
       Options:
         -debug           print commands executed by this script
         -explain         set compiler option -explain
         -explain-types   set compiler option -explain-types
         -main:<name>     define main class name (default: Main)
         -print           print IR after compilation phase 'lambdaLift'
         -scala2          use Scala 2 tools
         -scala3          use Scala 3 tools (default)
         -tasty           compile both from source and TASTy files
         -timer           print the execution time
         -verbose         print progress messages
      
       Subcommands:
         clean            delete generated files
         compile          compile Java/Scala source files
         decompile        decompile generated code with CFR
         doc              generate HTML documentation
         help             print this help message
         lint             analyze Scala source files with Scalafmt
         run[:i]          execute main class (instrumented execution: :i)
         test             execute unit tests with JUnit
      
       Properties:
       (to be defined in SBT configuration file project\build.properties)
         main.class       alternative to option -main:<name>
         main.args        list of arguments to be passed to main class
     

Optional tools

  1. Build tools

    Code examples in directories examples\ and myexamples\ can also be built with the following tools as an alternative to the build.bat command (see examples\README.md and myexamples\README.md for more details):

    Build tool Build file Parent file Usage example
    ant.bat build.xml build.xml antclean compile run
    bazel.exe BUILD n.a. bazelrun :enum-Planet
    cmd.exe build.bat build clean run
    gradle.bat build.gradle common.gradle gradleclean build run
    make.exe Makefile Makefile.inc makeclean run
    mill.bat build.sc common.sc mill -i app
    mvn.cmd pom.xml pom.xml mvnclean compile test
    sbt.bat build.sbt n.a. sbtclean compile run
  2. Decompiler tools

    As an alternative to the standard javap.exe class decompiler one may use cfr.bat (simply extract bin\cfr-0.152.zip to c:\opt\) which prints Java source code instead of Java bytecode:

     > cfr myexamples\00_AutoParamTupling\target\classes\myexamples\Main.class
     /*
      * Decompiled with CFR 0.152.
      */
     package myexamples;
     
     import myexamples.Main$;
     
     public final class Main {
         public static void test01() {
             Main$.MODULE$.test01();
         }
     
         public static void main(String[] arrstring) {
             Main$.MODULE$.main(arrstring);
         }
     
         public static void test02() {
             Main$.MODULE$.test02();
         }
     }
     

    Here is the console output from command javap.exe with option -c for the same class file:

     > javap -c myexamples\00_AutoParamTupling\target\classes\myexamples\Main.class
     Compiled from "Main.scala"
     public final class myexamples.Main {
       public static void main(java.lang.String[]);
         Code:
            0: getstatic     #13                 // Field myexamples/Main$.MODULE$:Lmyexamples/Main$;
            3: aload_0
            4: invokevirtual #15                 // Method myexamples/Main$.main:([Ljava/lang/String;)V
            7: return
     
       public static void test02();
         Code:
            0: getstatic     #13                 // Field myexamples/Main$.MODULE$:Lmyexamples/Main$;
            3: invokevirtual #19                 // Method myexamples/Main$.test02:()V
            6: return
     
       public static void test01();
         Code:
            0: getstatic     #13                 // Field myexamples/Main$.MODULE$:Lmyexamples/Main$;
            3: invokevirtual #22                 // Method myexamples/Main$.test01:()V
            6: return
     }
     

Usage examples

setenv.bat

We execute command setenv.bat once to setup our development environment; it makes external tools such as bazel.exe, mvn.cmd, sbt.bat and git.exe directly available from the command prompt.

> setenv
Tool versions:
   javac 17.0.13, scalac 2.13.15, scalac 3.3.4, scalafmt 3.7.17,
   ant 1.10.15, gradle 8.10.2, mvn 3.9.9, sbt 1.10.3, scala-cli 1.5.1,
   mill 0.12.1, bazel 7.4.0, cfr 0.152, make 3.81, python 3.11.1,
   jacoco 0.8.12, git 2.47.0, diff 3.10, bash 5.2.37(1)

> where sbt scala-cli
C:\opt\sbt\bin\sbt
C:\opt\sbt\bin\sbt.bat
C:\opt\scala-cli\scala-cli.exe

Other development tools such as javac.exe and scalac.bat are accessible through the corresponding environment variable, e.g. JAVA_HOME for javac.exe, SCALA_HOME resp. SCALA3_HOME for scalac.bat and PYTHON_HOME for python.exe.

> where javac
INFO: Could not find files for the given pattern(s).
 
> where /r %JAVA_HOME% javac
C:\opt\jdk-temurin-17.0.13_11\bin\javac.exe
 
> %JAVA_HOME%\bin\javac -version
javac 17.0.13

Command setenv.bat -verbose also prints the tool paths and defined environment variables:

> setenv -verbose
Tool versions:
   javac 17.0.13, scalac 2.13.15, scalac 3.3.4, scalafmt 3.7.12,
   ant 1.10.15, gradle 10, mvn 3.9.9, sbt 1.10.3, scala-cli 1.5.1,
   mill 0.12.1, bazel 7.4.0, cfr 0.152, make 3.81, python 3.11.1,
   jacoco 0.8.12, git 2.47.0, diff 3.10, bash 5.2.37(1)
Tool paths:
   C:\opt\jdk-temurin-11.0.21_9\bin\javac.exe
   C:\opt\scala-2.13.15\bin\scalac.bat
   C:\opt\scala3-3.3.4\bin\scalac.bat
   %LOCALAPPDATA%\Coursier\data\bin\scalafmt.bat
   C:\opt\apache-ant\bin\ant.bat
   C:\opt\gradle\bin\gradle.bat
   C:\opt\mill\mill.bat
   C:\opt\apache-maven\bin\mvn.cmd
   C:\opt\sbt\bin\sbt.bat
   C:\opt\scala-cli\scala-cli.exe
   C:\opt\mill\mill.bat
   C:\opt\bazel\bazel.exe
   C:\opt\cfr-0.152\bin\cfr.bat
   C:\opt\make-3.81\bin\make.exe
   C:\opt\Python-3.11.1\python.exe
   C:\opt\jacoco\lib\jacococli.jar
   C:\opt\Git\bin\git.exe
   C:\opt\Git\usr\bin\diff.exe
   C:\opt\Git\bin\bash.exe
Environment variables:
   "ANT_HOME=C:\opt\apache-ant"
   "BAZEL_HOME=c:\opt\bazel"
   "CFR_HOME=C:\opt\cfr-0.152"
   "COURSIER_DATA_DIR=%LOCALAPPDATA%\coursier\data"
   "COURSIER_HOME=C:\opt\coursier-2.1.7"
   "GIT_HOME=C:\opt\Git"
   "GRADLE_HOME=C:\opt\gradle"
   "JAVA_HOME=C:\opt\jdk-temurin-17.0.13_11"
   "JAVA17_HOME=C:\opt\jdk-temurin-17.0.13_11"
   "JAVA21_HOME=C:\opt\jdk-temurin-21.0.5_11"
   "JAVAFX_HOME=C:\opt\javafx-sdk-21.0.5"
   "MSVS_HOME=X:"
   "MSYS_HOME=C:\opt\msys64"
   "PYTHON_HOME=C:\opt\Python-3.11.1"
   "SBT_HOME=C:\opt\sbt"
   "SCALA_CLI_HOME=C:\opt\scala-cli"
   "SCALA_HOME=C:\opt\scala-2.13.15"
   "SCALA3_HOME=C:\opt\scala3-3.3.4"
   "SCALA3_NEXT_HOME=C:\opt\scala3-3.5.2"
Path associations:
   I:\: => %USERPROFILE%\workspace-perso\dotty-examples

cleanup.bat

Command cleanup.bat removes the output directories (ie. target\) from the example projects:

> cleanup
Finished to clean up 2 subdirectories in Y:\dotty\cdsexamples
Finished to clean up 16 subdirectories in Y:\dotty\examples
Finished to clean up 12 subdirectories in Y:\dotty\myexamples

dirsize.bat {<dir_name>}

Command dirsize.bat returns the size (in Kb, Mb or Gb) of the specified directory paths:

> dirsize examples myexamples c:\opt\scala3-3.3.4 c:\opt\jdk-temurin-17.0.13_11
Size of directory "examples" is 3.9 Mb
Size of directory "myexamples" is 1.2 Mb
Size of directory "c:\opt\scala3-3.3.4" is 35.7 Mb
Size of directory "c:\opt\jdk-temurin-17.0.13_11" is 304.0 Mb

getnightly.bat

By default command getnightly.bat downloads the library files of the latest Dotty nightly build available from the Maven Central Repository and saves them into directory out\nightly\.

> getnightly
Usage: getnightly { <option> | <subcommand> }
 
  Options:
    -debug      print commands executed by this script
    -timer      print total execution time
    -verbose    print download progress
 
  Subcommands:
    activate    activate the nightly build library files
    download    download nighty build files and quit (default)
    help        print this help message
    restore     restore the default Scala library files

Command getnightly.bat download with options -verbose also displays the download progress:

> getnightly -verbose download
Delete directory "out\nightly"
Download Scala 3 nightly files from Maven repository
Downloading file scala3-language-server_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 148.9 Kb
Downloading file scala3-compiler_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 20.3 Mb
Downloading file scala3-sbt-bridge-3.5.0-RC1-bin-20240514-7c9aae3-NIGHTLY.jar ... 31.2 Kb
Downloading file scala3-tasty-inspector_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 17.4 Kb
Downloading file scala3-library_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 1.2 Mb
Downloading file scala2-library-tasty-experimental_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 3 Mb
Downloading file scala3-staging_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 40.7 Kb
Downloading file scala3-presentation-compiler_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 1.7 Mb
Downloading file scala3-library_sjs1_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 1.9 Mb
Downloading file scala3-interfaces-3.5.0-RC1-bin-20240514-7c9aae3-NIGHTLY.jar ... 3.9 Kb
Downloading file scala2-library-cc-tasty-experimental_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 3 Mb
Downloading file scaladoc_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 4.7 Mb
Downloading file tasty-core_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar ... 94.5 Kb
Downloading file antlr4-runtime-4.7.2.jar ... 330 Kb
[...]
Downloading file common ... 6 Kb
Downloading file common.bat ... 2.9 Kb
Converting file common.bat to DOS format
Downloading file scala ... 1.8 Kb
Downloading file scala.bat ... 2.6 Kb
Converting file scala.bat to DOS format
Downloading file scalac ... 2.5 Kb
Downloading file scalac.bat ... 3.7 Kb
Converting file scalac.bat to DOS format
Downloading file scaladoc ... 5 Kb
Downloading file scaladoc.bat ... 4.6 Kb
Converting file scaladoc.bat to DOS format
Finished to download 54 files to directory "%LOCALAPPDATA%\Temp\scala3-nightly"
Retrieve revision for hash "3e105f2" from GitHub repository "lampepfl/dotty"
File "%LOCALAPPDATA%\Temp\scala3-nightly\VERSION":
version:=3.6.2-RC1-bin-20240514-7c9aae3-NIGHTLY
revision:=7c9aae3
buildTime:=2024-05-15 23:09:19+02:00

Output directory %TEMP%\scala3-nightly\ contains the two subdirectories bin\ and lib\:

> dir /b %TEMP%\scala3-nightly\bin %TEMP%\scala3-nightly\lib
common
common.bat
scala
scala.bat
scalac
scalac.bat
scaladoc
scaladoc.bat
antlr-runtime-4.7.2.jar
autolink-0.6.0.jar
[...]
scala-asm-9.6.0-scala-1.jar
scala-library-2.13.12.jar
scala2-library-cc-tasty-experimental_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scala2-library-tasty-experimental_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scala3-compiler_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scala3-interfaces-3.5.0-RC1-bin-20240514-7c9aae3-NIGHTLY.jar
scala3-language-server_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scala3-library_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scala3-library_sjs1_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scala3-presentation-compiler_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scala3-sbt-bridge-3.6.2-RC1-bin-20240514-7c9aae3-NIGHTLY.jar
scala3-staging_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scala3-tasty-inspector_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
scaladoc_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar
snakeyaml-2.0.jar
strftime4j-1.0.6.jar
tasty-core_3.6.2-RC1-bin-20241025-91ef921-NIGHTLY.jar

Concretely, subcommand activate switches to the nightly build version and subcommand restore restore the path to the Scala 3 installation directory.

> getnightly activate
Active Scala 3 installation is 3.6.2-RC1-bin-20241025-91ef921-NIGHTLY (was 3.3.4)

> %SCALA3_HOME%\bin\scalac -version
Scala compiler version 3.6.2-RC1 -- Copyright 2002-2024, LAMP/EPFL

> getnightly restore
Active Scala 3 installation is 3.3.4

> %SCALA3_HOME%\bin\scalac -version
Scala compiler version 3.3.4 -- Copyright 2002-2024, LAMP/EPFL

⚠️ You need write access to the Scala 3 installation directory (e.g. C:\opt\scala3-3.3.4\ in our case) in order to successfully run the activate/reset subcommands.

searchjars.bat <class_name>

Command searchjars.bat helps us to search for class file names in the following directories: project's lib\ directory (if present), Scala's lib\ directory, Java's lib\ directory and Ivy/Maven default local directories.

> searchjars -help
Usage: searchjars { <option> | <class_name> }
 
  Options:
    -artifact        search in ~\.ivy2 and ~\.m2 directories
    -help            print this help message
    -ivy             search in ~\.ivy directory
    -java            search in Java library directories
    -maven           search in ~\.m2 directory
    -scala           search in Scala library directories
    -verbose         print progress messages
 
  Arguments:
    <class_name>     class name

For instance we get the following output when passing class name System to command searchjars.bat (class file names are printed with full path and are prefixed with their containing JAR file):

> searchjars System
Searching for class name System in archive files C:\opt\scala3-3.3.4\lib\*.jar
  jline-reader-3.19.0.jar:org/jline/reader/impl/completer/SystemCompleter.class
  scala-library-2.13.15.jar:scala/sys/SystemProperties$.class
  scala-library-2.13.15.jar:scala/sys/SystemProperties.class
Searching for class name System in archive files C:\opt\scala-2.13.15\lib\*.jar
  jline-3.19.0.jar:org/jline/builtins/SystemRegistryImpl$CommandOutputStream.class
  [...]
  scala-library.jar:scala/sys/SystemProperties$.class
  scala-library.jar:scala/sys/SystemProperties.class
Searching for class name System in archive files C:\opt\jdk-temurin-17.0.13_11\lib\*.jar
  jrt-fs.jar:jdk/internal/jrtfs/JrtFileSystem$1.class
  [...]
  jrt-fs.jar:jdk/internal/jrtfs/SystemImage$2.class
  jrt-fs.jar:jdk/internal/jrtfs/SystemImage.class
Searching for class name System in archive files c:\opt\javafx-sdk-17.0.13_11\lib\*.jar
  javafx.graphics.jar:com/sun/glass/ui/SystemClipboard.class
  [...]
  javafx.graphics.jar:com/sun/javafx/tk/TKSystemMenu.class
  javafx.web.jar:com/sun/webkit/FileSystem.class

Searching for an unknown class name - e.g. BinarySearch - produces the following output:

> searchjars BinarySearch
Searching for class name BinarySearch in archive files C:\opt\scala3-3.3.4\lib\*.jar
Searching for class name BinarySearch in archive files C:\opt\scala-2.13.15\lib\*.jar
Searching for class name BinarySearch in archive files C:\opt\jdk-temurin-17.0.13_11\lib\*.jar

Searching for FileSystem with option -artifact produces the following output:

> searchjars FileSystem -artifact
Searching for class name FileSystem in archive files C:\opt\scala3-3.3.4\lib\*.jar
Searching for class name FileSystem in archive files C:\opt\scala-2.13.15\lib\*.jar
Searching for class name FileSystem in archive files c:\opt\jdk-temurin-17.0.13_11\lib\*.jar
  jrt-fs.jar:jdk/internal/jrtfs/JrtFileSystem$1.class
  jrt-fs.jar:jdk/internal/jrtfs/JrtFileSystem.class
  jrt-fs.jar:jdk/internal/jrtfs/JrtFileSystemProvider$1.class
  jrt-fs.jar:jdk/internal/jrtfs/JrtFileSystemProvider$JrtFsLoader.class
  jrt-fs.jar:jdk/internal/jrtfs/JrtFileSystemProvider.class
Searching for class name FileSystem in archive files c:\opt\javafx-sdk-17\lib\*.jar
  javafx.web.jar:com/sun/webkit/FileSystem.class
Searching for class name FileSystem in archive files %USERPROFILE%\.ivy2\cache\*.jar
  okhttp-3.14.2.jar:okhttp3/internal/io/FileSystem$1.class
  okhttp-3.14.2.jar:okhttp3/internal/io/FileSystem.class
  ivy-2.3.0-sbt-839fad1cdc07cf6fc81364d74c323867230432ad.jar:org/apache/ivy/plugins/resolver/FileSystemResolver.class
  ivy-2.3.0-sbt-88d6a93d15f9b029958c1c289a8859e8dfe31a19.jar:org/apache/ivy/plugins/resolver/FileSystemResolver.class
  ivy-2.3.0-sbt-fa726854dd30be842ff9e6d2093df6adfe3871f5.jar:org/apache/ivy/plugins/resolver/FileSystemResolver.class
Searching for class name FileSystem in archive files %USERPROFILE%\.m2\repository\*.jar
  commons-io-2.2.jar:org/apache/commons/io/FileSystemUtils.class
  commons-io-2.5.jar:org/apache/commons/io/FileSystemUtils.class
  commons-io-2.6.jar:org/apache/commons/io/FileSystemUtils.class
  ivy-2.4.0.jar:org/apache/ivy/plugins/resolver/FileSystemResolver.class
  sigar-1.6.4.jar:org/hyperic/sigar/FileSystem.class
  [...]
  stagemonitor-os-0.88.9.jar:org/stagemonitor/os/metrics/FileSystemMetricSet.class

timeit.bat <cmd_1> { & <cmd_i> }

Batch file timeit.bat prints the execution time (hh:MM:ss format) of the specified command (possibly given with options and parameters):

> timeit dir /b
.gitignore
.gradle
build.bat
build.gradle
build.sbt
build.sc
build.xml
pom.xml
project
settings.gradle
src
target
Execution time: 00:00:01
 
> timeit build clean compile
Execution time: 00:00:08

Chaining of commands is also possible. Note that the command separator (either && or &) must be escaped if the command chain is not quoted. For instance:

s
> timeit build clean compile ^&^& ant run
...
Execution time: 00:00:11
> timeit "build clean compile && ant run"
...
Execution time: 00:00:11

🔎 The && command separator performs error checking - that is, the commands to the right of the && command run if and only if the command to the left of && succeeds. The & command does not perform error checking - that is, all commands run.

build.bat

Batch file build.bat is a basic build script consisting of ~800 lines of batch/Powershell code 7.

Running command build.bat with no option in project examples\enum-Planet generates the following output:

> build clean compile run
Your weight on MERCURY (0) is 0.37775761520093526
Your weight on SATURN (5) is 1.0660155388115666
Your weight on VENUS (1) is 0.9049990998410455
Your weight on URANUS (6) is 0.9051271993894251
Your weight on EARTH (2) is 0.9999999999999999
Your weight on NEPTUNE (7) is 1.1383280724696578
Your weight on MARS (3) is 0.37873718403712886
Your weight on JUPITER (4) is 2.5305575254957406

More usage examples are presented in examples\README.md resp. myexamples\README.md

scala.bat

Scala REPL is an interactive tool for evaluating Scala expressions. Internally, it executes a source script by wrapping it in a template and then compiling and executing the resulting program.

⚠️ Batch file scala.bat is based on the bash script scala available from the standard Scala 3 distribution. We also have submitted pull request #5444 to add that batch file to the Scala 3 distribution.

> where scala
C:\opt\scala3-3.3.4\bin\scala
C:\opt\scala3-3.3.4\bin\scala.bat

> scala -version
Scala code runner version 3.3.4 -- Copyright 2002-2024, LAMP/EPFL

> scala
Starting scala REPL...
scala> :help
The REPL has several commands available:

:help                    print this summary
:load <path>             interpret lines in a file
:quit                    exit the interpreter
:type <expression>       evaluate the type of the given expression
:imports                 show import history
:reset                   reset the repl to its initial state, forgetting all session entries

scala> System.getenv().get("JAVA_HOME")
val res0: String = C:\opt\jdk-temurin-17.0.13_11

scala> System.getenv().get("SCALA3_HOME")
val res1: String = C:\opt\scala3-3.3.4

scala> :load myexamples/HelloWorld/src/main/scala/HelloWorld.scala
// defined object HelloWorld

scala> HelloWorld.main(Array())
Hello world!

scala>:quit

Footnotes

[1] Scala 3 LTS versions

The distinction between LTS and Next versions of Scala 3 is presented on the page "Long-term compatibility plans for Scala 3" posted on August 17, 2022.

In particular it makes the following statement : "We suggest end users stick to the LTS version. It will give you the best tooling support and a stable compiler. If you are migrating a bigger project from Scala 2, you should migrate it straight to the newest LTS."

[2] Java LTS versions

Oracle annonces in his Java SE Support Roadmap he will stop public updates of Java SE 8 for commercial use after January 2019. Current LTS versions are (from Oracle's support roadmap):
Java LTS VersionGAEnd of life
25 September 2025 September 2033
21 September 2023 September 2031
17 September 2021 September 2029
11 September 2018 September 2026
8 March 2014 December 2030 (1)
(1) The Extended Support uplift fee will be waived for the period March 2022 - December 2030 for Java SE 8.
NB. See also Zulu's support roadmap.

[3] Using Bazel on Windows

See also the Support matrix on the Bazel website.
Bazel LTS VersionGAEnd of support
8.0.0 Late 2024 -
7.4.0 October 2024 December 2026
7.3.1 December 2023 December 2026
6.5.0 December 2022 December 2025
5.4.1 January 2022 January 2025
Read the page Builds on Windows of the Bazel website for tips to build with MSVC, Clang, Java or Python on a Windows machine.
For instance, for Visual Studio 2019, we set variable BAZEL_VC to the Visual C++ Build Tools installation directory:
> set "BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC"

[4] JaCoCo and Java support

JaCoCo version Supported Java version Depends on ASM
0.8.12 (March 2024) 21 and 22 9.7
0.8.11 (Oct 2023) 21 and 22 9.6
0.8.10.2 (April 2023) 19 and 20 9.5
0.8.9 (March 2023) 19 and 20 9.5
0.8.8 (April 2022)17 and 189.2
0.8.7 (May 2021)15 and 169.1
0.8.6 (Sept 2020)148.2
0.8.5 (Oct 2019)137.2
0.8.4 (May 2019)127.1
0.8.3 (Jan 2019)117.0
0.8.2 (Aug 2018) 6.3.2
0.8.1 (March 2018)10 
0.8.0 (Jan 2018)96.0

[5] Scala 3 Next

The attentive Scala 3 user will have noticed that the size of the Scala 3 software distribution has increased significantly with version 3.5.0.
Scala 3 VersionArchive sizeInstallation size
3.3.4 LTS34 MB38.6 MB
3.5.0 Next70 MB131 MB
That size increase of the Scala 3 software distribution comes from a big reorganization of its contents :
  • scala-cli (91 MB) from VIRTUSLAB is now part of the distribution
  • directory lib\ now contains only 3 JAR files: .
  • directory maven2\ (40 MB) is new; this application specific Maven repository contains the Maven packages Scala 3 depends on.
The section "Class-Path Attribute" of the Java Platform Specification describes the usage the manifest attribute Class-Path. We present its usage in the manifest file lib\scala.jar\META-INF\MANIFEST.MF :
Manifest-Version: 1.0
Class-Path: ../maven2/org/scala-lang/scala3-interfaces/3.5.0/scala3-in
 terfaces-3.5.0.jar ../maven2/org/scala-lang/scala3-compiler_3/3.5.0/s
 cala3-compiler_3-3.5.0.jar ../maven2/org/scala-lang/scala3-library_3/
 3.5.0/scala3-library_3-3.5.0.jar ../maven2/org/scala-lang/tasty-core_
 3/3.5.0/tasty-core_3-3.5.0.jar ../maven2/org/scala-lang/modules/scala
 -asm/9.6.0-scala-1/scala-asm-9.6.0-scala-1.jar ../maven2/org/scala-sb
 t/compiler-interface/1.9.6/compiler-interface-1.9.6.jar ../maven2/org
 /jline/jline-reader/3.25.1/jline-reader-3.25.1.jar ../maven2/org/jlin
 e/jline-terminal/3.25.1/jline-terminal-3.25.1.jar ../maven2/org/jline
 /jline-terminal-jna/3.25.1/jline-terminal-jna-3.25.1.jar ../maven2/or
 g/scala-lang/scala-library/2.13.15/scala-library-2.13.15.jar ../maven
 2/org/scala-sbt/util-interface/1.9.8/util-interface-1.9.8.jar ../mave
 n2/org/jline/jline-native/3.25.1/jline-native-3.25.1.jar ../maven2/ne
 t/java/dev/jna/jna/5.14.0/jna-5.14.0.jar
 

[6] Downloads

In our case we downloaded the following installation files (see section 1):
0.12.1-assembly (mill)                             ( 64 MB)
apache-ant-1.10.15-bin.zip                         (  9 MB)
apache-maven-3.9.9-bin.zip                         ( 10 MB)
bazel-7.4.0-windows-x86_64.zip                     ( 40 MB)
gradle-8.10.2-bin.zip                              (124 MB)
jacoco-0.8.12.zip                                  (  4 MB)
jitwatch-ui-1.4.9-shaded-win.jar                   ( 36 MB)
msys2-x86_64-20240727.exe                          ( 94 MB)
OpenJDK8U-jdk_x64_windows_hotspot_8u432b06.zip     ( 99 MB)
OpenJDK17U-jdk_x64_windows_hotspot_17.0.13_11.zip  (188 MB)
OpenJDK21U-jdk_x64_windows_hotspot_21.0.5_11.zip   (191 MB)
openjfx-17.0.13_windows-x64_bin-sdk.zip            ( 39 MB)
openjfx-17.0.13_windows-x64_bin-jmods.zip          ( 37 MB)
openjfx-21.0.5_windows-x64_bin-sdk.zip             ( 39 MB)
openjfx-21.0.5_windows-x64_bin-jmods.zip           ( 37 MB)
PortableGit-2.47.0-64-bit.7z.exe                   ( 60 MB)
sbt-1.10.3.zip                                     ( 17 MB)
scala-2.13.15.zip                                  ( 22 MB)
scala-cli-x86_64-pc-win32.zip                      ( 31 MB)
scala3-3.3.4.zip                                   ( 34 MB)
scala3-3.5.2.zip                                   (123 MB)

[7] PowerShell

Command Prompt has been around for as long as we can remember, but starting with Windows 10 build 14971, Microsoft is trying to make PowerShell the main command shell in the operating system.

mics/November 2024