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, 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.
This project depends on the following external software for the Microsoft Windows platform:
Optionally one may also install the following software:
- Apache Ant 1.10 (requires Java 8) (release notes)
- Apache Maven 3.9 (requires Java 8+) (release notes)
- ConEmu 2023 (release notes)
- detekt 1.23 (release notes)
- Gradle 8.10 (release notes)
- KtLint 1.3 2 (release notes)
- Temurin OpenJDK 11 LTS 1 (release notes, bug fixes)
- Temurin OpenJDK 17 LTS 1 (release notes, bug fixes)
- Visual Studio Code 1.93 (release notes)
For instance our development environment looks as follows (October 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.12_7\ (301 MB) C:\opt\kotlinc\ ( 90 MB) C:\opt\kotlin-native\ (242 MB) C:\opt\ktlint\ ( 77 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 definedC:\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
- directory
bin\
contains several batch files. - file
bin\kotlin\build.bat
is the batch script for generating the Kotlin software distribution on a Windows machine. - directory
concurrency-in-kotlin\
contains Kotlin code examples (seeconcurrency-in-kotlin\README.md
) - directory
docs\
contains Kotlin related papers/articles. - directory
examples\
contains Kotlin code examples (see documentexamples\README.md
). - directory
how-to-kotlin\
contains Kotlin code examples (seehow-to-kotlin\README.md
). - directory
kotlin\
contains a copy of the JetBrains/kotlin repository as a Github submodule. - directory
kotlin-cookbook\
contains Kotlin code examples (seekotlin-cookbook\README.md
). - directory
learn-kotlin\
contains Kotlin code examples (seelearn-kotlin\README.md
). - file
CONTRIBUTIONS.md
gathers reported issues and pull requests to the Kotlin project. - file
LANGUAGE.md
resumes Kotlin language changes. - file
README.md
is the Markdown document for this page. - file
RESOURCES.md
is the Markdown document presenting external resources. - file
setenv.bat
is the batch script for setting up our environment.
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.10.2, java 17.0.10, detekt-cli 1.23.7, kotlinc 2.0.21-RC, kotlinc-native 2.0.21-RC, ktlint 1.3.1, cfr 0.152, make 3.81, mvn 3.9.9, git 2.46.2, diff 3.10, bash 4.4.26(1) Tool paths: C:\opt\apache-ant\bin\ant.bat C:\opt\gradle\bin\gradle.bat C:\opt\jdk-temurin-17.0.12_7\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.12_7" "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/Native LLVM 2.0.0 - 2.0.21-RC 11.1.0 (16.0.0 WIP) 1.9.10 - 1.9.23 11.1.0 1.9.0 11.1.0 1.8.20 11.1.0 1.8.0 11.1.0 1.7.20 11.1.0 1.6.0 11.1.0 1.3.60 8.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 filektlint_header.bin
and the extracted JAR file.
- we create an installation directory
- Here are the performed operations:
-
> mkdir c:\opt\ktlint\bin > cd c:\opt\ktlint\bin > curl -sL -o ktlint.sh https://github.com/pinterest/ktlint/releases/download/1.3.1/ktlint > tail -n+5 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.3.1
[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.10.2-bin.zip (115 MB) kotlin-compiler-2.0.21-RC.zip ( 80 MB) kotlin-native-windows-x86_64-2.0.21-RC.zip (169 MB) ktlint (1.3.1) ( 63 MB) make-3.81-bin.zip ( 10 MB) OpenJDK11U-jdk_x64_windows_hotspot_17.0.12_7.zip ( 99 MB) PortableGit-2.46.2-64-bit.7z.exe ( 43 MB) VSCode-win32-x64-1.92.1.zip (131 MB)