Generating Kotlin code from Protocol Buffers (without JVN on your host)

Gradle? JVM? Looks as chainsaw in this case.

Protocol Buffers is famous IDL(Interface Description Language) in these days. And the uber/prototool is needful tool for generating interface codes in any languages.

However information about generating kotlin code is quiet few in today.

Basically I was knowledgeless about kotlin before generating kotlin codes. And the our project is written in golang.

Okay, then I found an entry that telling as “JVM and gradle are needed when generating kotlin code through protoc”.

Hmm, “place build.gradle will be in our project”? Sounds not so good. Because our project is written in golang. Don’t forget, I just want “generating kotlin codes from protocol buffers“. This method looks as cutting sashimi with chainsaw.

Conclusion: Docker solves as like sashimi knife

In this case, requirement to environment for solving the issue is so huge. “Huge requirement to environment… I’ve got it!” yes, it is the Docker Hub. So I found the container image that fits this case.

It is the moia/prototool-docker (codes on GitHub).

Usage is followings.

1
2
3
4
5
6
7
8
9
10
11
12
### prototool.dockerfile
FROM moia/prototool-docker

RUN mkdir /proj
WORKDIR /proj

CMD protoc --kotlin_out=./proto/kotlin ./proto/definition/*.proto

### In your terminal
$ docker build -f ./prototool.dockerfile -t prototool .
$ docker run --rm -v /path/to/myproj:/proj -t prototool

Finally I got succeed to generate kotlin code from protocol buffers, with moia/prototool-docker that is instead of JVM on my host.