Skip to content

michelou/kotlin-examples

Repository files navigation

Playing with Kotlin on Windows

Kotlin project This repository gathers Kotlin code examples coming from various websites and books.
It also includes several build scripts (Bash scripts, batch files, Gradle scripts, Maven scripts) for experimenting with Kotlin on a Windows machine.

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

Read the document "Kotlin Language Specification" to know more about of the design decisions behind the Kotlin programming language.

Project dependencies

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

Optionally one may also install the following software:

For instance our development environment looks as follows (December 2024) 3:

C:\opt\apache-ant\               ( 44 MB)
C:\opt\apache-maven\             (  9 MB)
C:\opt\ConEmu\                   ( 26 MB)
C:\opt\detekt-cli\               ( 67 MB)
C:\opt\Git\                      (389 MB)
C:\opt\gradle\                   (144 MB)
C:\opt\jdk-temurin-17.0.13_11\   (304 MB)
C:\opt\kotlinc\                  ( 90 MB)
C:\opt\kotlin-native\            (242 MB)
C:\opt\ktlint\                   ( 70 MB)
C:\opt\make-3.81\                (  2 MB)
C:\opt\VSCode\                   (370 MB)

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).

Directory structure

This project is organized as follows:

bin\
bin\kotlin\build.bat
concurrency-in-kotlin\{README.md}
docs\
examples\{README.md, HelloWorld, JavaToKoltin, ..}
how-to-kotlin\{README.md, 01_bean, 02_properties, ..}
kotlin\   (Github submodule)
kotlin-cookbook\{README.md, Example_03-10, Example_03-13, ..}
learn-kotlin\{README.md, Unit_02, Unit_04, ..}
CONTRIBUTIONS.md
LANGUAGE.md
README.md
RESOURCES.md
setenv.bat

where

We also define a virtual drive – e.g. drive I: – 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).

🔎 We use the Windows external command subst to create virtual drives; for instance:

> subst I: %USERPROFILE%\workspace\kotlin-examples

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

Batch commands

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

> setenv -verbose
Tool versions:
   ant 1.10.15, gradle 8.11.1, java 17.0.13, detekt-cli 1.23.7,
   kotlinc 2.1.0, kotlinc-native 2.1.0, ktlint 1.5.0, cfr 0.152,
   make 3.81, mvn 3.9.9, git 2.47.1, diff 3.10, bash 4.4.37(1)
Tool paths:
   C:\opt\apache-ant\bin\ant.bat
   C:\opt\gradle\bin\gradle.bat
   C:\opt\jdk-temurin-17.0.23_11\bin\java.exe
   C:\opt\detekt-cli\bin\detekt-cli.bat
   C:\opt\kotlinc\bin\kotlinc.bat
   C:\opt\kotlin-native\bin\kotlinc-native.bat
   C:\opt\ktlint\ktlint.bat
   C:\opt\cfr-0.152\bin\cfr.bat
   C:\opt\make-3.81\bin\make.exe
   C:\opt\apache-maven\bin\mvn.cmd
   C:\opt\Git\bin\git.exe
   C:\opt\Git\mingw64\bin\git.exe
   C:\opt\Git\usr\bin\diff.exe
Environment variables:
   "ANT_HOME=C:\opt\apache-ant"
   "CFR_HOME=C:\opt\cfr-0.152"
   "DETEKT_HOME=C:\opt\detekt-cli"
   "GIT_HOME=C:\opt\Git"
   "GRADLE_HOME=C:\opt\gradle"
   "JAVA_HOME=C:\opt\jdk-temurin-17.0.23_11"
   "KOTLIN_HOME=C:\opt\kotlinc"
   "KOTLIN_NATIVE_HOME=C:\opt\kotlin-native"
   "KTLINT_HOME=C:\opt\ktlint"
   "MAKE_HOME=C:\opt\make-3.81"
   "MAVEN_HOME=C:\opt\apache-maven"

This batch command generates the Kotlin binary distribution on a Windows machine.

Footnotes

[1] Kotlin/Native

Kotlin/Native is an LLVM backend for the Kotlin compiler, runtime implementation, and native code generation facility using the LLVM toolchain.
Kotlin/NativeLLVM
2.0.0 - 2.1.011.1.0 (16.0.0 WIP)
1.9.10 - 1.9.2311.1.0
1.9.011.1.0
1.8.2011.1.0
1.8.011.1.0
1.7.2011.1.0
1.6.011.1.0
1.3.608.0

[2] KtLint on Windows

No Windows distribution is available from the KtLint repository.
Fortunately the KtLint tool is packed into a shell script (i.e. embedded JAR file in binary form), so we simply extracted the JAR file to create a "universal" KtLint distribution (in the same way as the Mill assembly distribution):
  • we create an installation directory c:\opt\ktlint\bin.
  • we download the shell script from the Github repository pinterest/ktlint.
  • we extract the JAR file from the bash script (and check it with command jar tf).
  • we create batch file ktlint.bat from the binary concatenation of header file ktlint_header.bin and the extracted JAR file.
Here are the performed operations:
NB. Drive i: is introduced in section "Directory structure".
> mkdir c:\opt\ktlint\bin
> cd c:\opt\ktlint\bin
 
> curl -sL -o ktlint.sh https://github.com/pinterest/ktlint/releases/download/1.5.0/ktlint
> tail -n+13 ktlint.sh > ktlint.jar
> %JAVA_HOME%\bin\jar tf ktlint.jar | findstr ktlint/Main
com/pinterest/ktlint/Main.class
> copy /y /b i:\bin\ktlint_header.bin + /b ktlint.jar ktlint.bat
The installation directory now contains one single file, namely ktlint.bat:
> dir /b c:\opt\ktlint\bin
ktlint.bat
 
> c:\opt\ktlint\bin\ktlint.bat --version
1.5.0

[3] Downloads

In our case we downloaded the following installation files (see section 1):
apache-ant-1.10.15-bin.zip                         (  9 MB)
apache-maven-3.9.9-bin.zip                         (  9 MB)
ConEmuPack.230724.7z                               (  5 MB)
detekt-cli-1.23.7.zip                              ( 54 MB)
gradle-8.11.1-bin.zip                              (115 MB)
kotlin-compiler-2.1.0.zip                          ( 80 MB)
kotlin-native-windows-x86_64-2.1.0.zip             (169 MB)
ktlint (1.5.0)                                     ( 63 MB)
make-3.81-bin.zip                                  ( 10 MB)
OpenJDK11U-jdk_x64_windows_hotspot_17.0.23_11.zip  ( 99 MB)
PortableGit-2.47.1-64-bit.7z.exe                   ( 43 MB)
VSCode-win32-x64-1.96.0.zip                        (131 MB)

mics/December 2024  

About

Playing with Kotlin on Windows

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages