Compiled kotlin with cli with docker and created an environment that can be executed with java

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.

What was made

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

How to use

Preparation

Just run the following command in the directory where docker-compose.yml is located.

$ docker-compose build
$ docker-compose up

Move

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

at the end

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!

Recommended Posts

Compiled kotlin with cli with docker and created an environment that can be executed with java
Create an environment where CircleCI can be executed locally with Windows10 + WSL2 (Ubuntu) + Docker
Prepare a scraping environment with Docker and Java
Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop
Graph the sensor information of Raspberry Pi and prepare an environment that can be checked with a web browser
Problems that can easily be mistaken for Java and JavaScript
Syntax and exception occurrence conditions that can be used when comparing with null in Java
Build an environment where pip3 can be used with CentOS7 + Python3
Introduction to Java that can be understood even with Krillin (Part 1)
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
Simple slot machine implementation that can be used with copy and paste
Launching the production environment with docker + rails (ver5.2) and errors that occurred
Performance analysis and failure diagnostic tools that can be used with OpenJDK
Building Rails 6 and PostgreSQL environment with Docker
Build an environment with Docker on AWS
Lightweight PHP 7.4 development environment created with Docker
Install Docker and create Java runtime environment
A memo that installed Ubuntu 20.4 on HP Z2 Mini G4 and created a deep learning environment with Python Docker
I installed WSL2 without using Microsoft Store and tried to build an environment where Docker can be used
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
Create an ARM-cpu environment with qemu on mac and run java [Result → Failure]
Build Apache and Tomcat environment with Docker. By the way, Maven & Java cooperation
Check with Java / Kotlin that files cannot be written in UAC on Windows
Make SpringBoot1.5 + Gradle4.4 + Java8 + Docker environment compatible with Java11
Build an E2E test environment with Selenium (Java)
Rails development environment created with VSCode and devcontainer
You can eliminate @Param with Kotlin 1.1 and MyBatis 3.4.1+! !!
[Ruby] Methods that can be used with strings
[Rails] How to build an environment with Docker
[First team development ②] Build an environment with Docker
Write a class that can be ordered in Java
Build an environment of Ruby2.7.x + Rails6.0.x + MySQL8.0.x with Docker
Easily build a Vue.js environment with Docker + Vue CLI
Create an E2E test environment with Docker x Cypress
Play with Java function nodes that can use Java with Node-RED
[First team development ③] Share the development environment created with Docker
[Note] Create a java environment from scratch with docker
I want to transition screens with kotlin and java!
Build Java development environment with WSL2 Docker VS Code
Prepare the environment for java11 and javaFx with Ubuntu 18.4
Build WordPress environment with Docker (Local) and AWS (Production)
Creating a lightweight Java environment that runs on Docker
Connect to Access database with Java [UCan Access] * Set until it can be executed with VS Code
[Java 8] Sorting method in alphabetical order and string length order that can be used in coding tests
We have improved Easy Markdown and prepared a docker image that can be built immediately.
(For myself) Build an IDE that you can touch from a browser with docker (trial)
How to create an environment that uses Docker (WSL2) and Vagrant (VirtualBox) together on Windows
Start jnlp that has expired and can no longer be started without using Java Web Start
How to change Java version and execute in an environment where Java cannot be installed freely