# Compiling a Kotlin application with Bazel

DevFeed: [Compiling a Kotlin application with Bazel](<https://devfeed.tech/articles/compiling-a-kotlin-application-with-bazel-21769.md>)

Original publisher: [Read original article](<https://enoent.fr/posts/creating-a-blog-with-bazel/02-compiling-a-kotlin-application-with-bazel/>)

Author: Marc Plano-Lesay

Published: 2019-12-08T00:30:00Z

Content type: tutorial

Language: en

Sources: [Marc Plano-Lesay](<https://devfeed.tech/sources/marc-plano-lesay.md>)

Topics: [bazel](<https://devfeed.tech/topics/bazel.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Dagger](<https://devfeed.tech/topics/dagger.md>), [Maven](<https://devfeed.tech/topics/maven.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>)

Tags: [annotation-processor](<https://devfeed.tech/tags/annotation-processor.md>), [bazel](<https://devfeed.tech/tags/bazel.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [dependency](<https://devfeed.tech/tags/dependency.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>)

## AI overview

A tutorial on compiling a small Kotlin application with Bazel. It explains the Phosphorus application's structure, its image-comparison purpose, Maven dependencies, rules_jvm_external, tests, Dagger's annotation processor, and Kotlin integration.

## Source excerpt

This post will describe how to compile a small application written in Kotlin using Bazel, tests, as well as how to use static analyzers. Phosphorus Phosphorus is the application that this post will cover. It's a small utility that I wrote to check if an image matches a reference. If it doesn't, Phosphorus generates an image highlighting the differences. The goal is to be able to check that something generates an image in a given way, and doesn't change - at least if it's not expected. The actual usage will be covered later in this series. While it's not open-source yet, it's something I intend to do at some point. It's written in Kotlin, as a couple external dependencies ( Clikt and Dagger), as well as a few tests. This is the structure: classDiagram namespace loader { class ImageLoader { <<interface>> } class ImageIoLoader { } } namespace differ { class ImageDiffer { <<interface>> } class ImageDifferImpl { } } namespace data { class Image class DiffResult } class Phosphorus ImageIoLoader ..|> ImageLoader ImageDifferImpl ..|> ImageDiffer Phosphorus --> ImageLoader Phosphorus --> ImageDiffer Phosphorus's class diagram The differ module contains the core logic - comparing two images, and generating a DiffResult. This DiffResult contains both the straightforward result of the comparison (are the two images identical?) and an image highlighting the differences, if any. The loader package is responsible for loading and writing images. Finally, the Phosphorus class orchestrates all that, in addition to processing command line arguments with Clikt. Dependencies Phosphorus has two dependencies: Clikt, and Dagger. Both of them are available as Maven artifacts. In order to pull Maven artifacts, the Bazel team provides a set of rules called rules_jvm_external. The idea is the following: you list a bunch of Maven coordinates and repositories, the rule will fetch all of them (and their transitive dependencies) during the loading phase, and generate Bazel targets corresponding to