I wanted to study kotlin for the first time, but I didn't like to have the kotlin compiler on my mac, so I made a set with docker compose. I do not assume that I will use a build tool, but I created it based on the concept of preparing an environment where you can check while running the simple grammar of kotlin. If you need it, please refer to it.
./docker-compose.yml
version: "3.7"
services:
java:
build: ./docker/java
tty: true
volumes:
- ./src:/usr/local/src
./docker/java/Dockerfile
FROM openjdk:13-slim
RUN apt-get update && apt-get install -y git \
unzip \
zip \
curl \
vim
WORKDIR /usr/local/src
RUN curl -s https://get.sdkman.io | bash
RUN /bin/bash -l -c "chmod a+x $HOME/.sdkman/bin/sdkman-init.sh;$HOME/.sdkman/bin/sdkman-init.sh;sdk install kotlin"
CMD ["/bin/bash"]
The directory structure is as follows
.
├── docker
│ └── java
│ └── Dockerfile
├── docker-compose.yml
└── src
└── test.kt
Just run the following command in the directory where docker-compose.yml is located.
$ docker-compose build
$ docker-compose up
In fact, compile test.kt
and run it with the java
command.
The target to compile is ./src/test.kt
.
fun main(args: Array<String>) {
println("Hello, World!")
}
Enter the container, compile and run.
$ docker-compose exec java bash
root@3b62768acd0b:/usr/local/src# kotlinc test.kt -include-runtime -d test.jar
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
root@3b62768acd0b:/usr/local/src# java -jar test.jar
Hello, World!
root@3b62768acd0b:/usr/local/src#
I get a warning that -Xverify: none
is useless, but I was able to compile and execute it with the java command.
Furthermore, since / usr / local / src
is volume-mounted, the jar file created after compilation can also be confirmed on the file system of the host machine.
.
├── docker
│ └── java
│ └── Dockerfile
├── docker-compose.yml
└── src
├── test.jar
└── test.kt
As you continue to study, you may want to use the build tool or have various inconveniences, but once the environment is in place, I want to study more and more!