# This is executable Markdown that's tested on CI.
# How is that possible? See https://gist.github.com/bwoods/1c25cb7723a06a076c2152a2781d4d49
set -o errexit -o nounset -o xtrace
alias ~~~=":<<'~~~sh'";:<<'~~~sh'
This repo includes:
- 🧱 Latest version of Bazel and dependencies
- 📦 Curated bazelrc flags via bazelrc-preset.bzl
- 🧰 Developer environment setup with bazel_env.bzl
- 🎨
ktfmtandktlint, using rules_lint - ✅ Pre-commit hooks for automatic linting and formatting
- 📚 Maven package manager integration
First, we recommend you setup a Bazel-based developer environment with direnv.
- install https://direnv.net/docs/installation.html
- run
direnv allowand follow the prompts tobazel run //tools:bazel_env
This isn't strictly required, but the commands which follow assume that needed tools are on the PATH,
so skipping direnv means you're responsible for installing them yourself.
First create some Kotlin source code:
mkdir src
>src/Demo.kt cat <<EOF
package app
class Demo {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println("Hello from Kotlin")
}
}
}
EOFThen run the BUILD file generation:
bazel run gazelleYou can check ktlint at this point:
aspect lint //src:allThis doesn't include Java support yet, so we need to run a couple commands to manually create the java_binary target:
buildozer 'new_load @rules_java//java:java_binary.bzl java_binary' src:__pkg__
buildozer 'new java_binary app' src:__pkg__
buildozer 'set main_class app.Demo' src:app
buildozer 'add runtime_deps :src' src:appNow we can verify that the application runs and produces the expected output:
output="$(bazel run src:app)"
[ "${output}" = "Hello from Kotlin" ] || {
echo >&2 "Wanted output 'Hello from Kotlin' but got '${output}'"
exit 1
}Run ktlint:
aspect lint