xkit.build v0.1.0

Buildeverything.One tool.

One small build language and one command line for Kotlin, Java, Android, C, C++ and Go. xkit downloads its own JDK, compilers and libraries, and project.lock pins every library and plugin.

Install · macOS on Apple silicon
curl -L https://github.com/xkit-build/xkit/releases/latest/download/xkit-aarch64-apple-darwin.tar.gz | tar xz && mv xkit-aarch64-apple-darwin/xkit ~/.local/bin/
~/shop
~/shop  xkit[gateway] Running go build[api] JDK ~/.xkit/jdks/temurin-21-macos-aarch64/Contents/Home[api] Resolving dependencies (Kotlin 2.4.21)[api] Compiling 1 Kotlin file(s)[pricing] Compiling 1 C/C++ file(s)[gateway] Done: ~/shop/gateway/build/commands/gateway/gateway[pricing] Done: ~/shop/pricing/build/lib/libpricing.a[api] Done: ~/shop/api/build/libs/api.jar~/shop  xkit[gateway] Up to date[api] Up to date[pricing] Up to date
A real build of a workspace with a Kotlin app, a C++ library and a Go program, built twice: the second build is up to date.

02 / The build language

Your build script
is a real language.

Java has no official build tool, only a third-party one, Maven, and a third party on top of that, Gradle. The same program in both worlds: a Kotlin app with Gson that starts with java -jar.

pom.xml · Maven 94 lines
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>hello</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <properties>
        <kotlin.version>2.4.21</kotlin.version>
        <maven.compiler.release>21</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <main.class>MainKt</main.class>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.14.0</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <testSourceDirectory>src/test/kotlin</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <jvmTarget>21</jvmTarget>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.4.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>${main.class}</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.8.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
project.build · xkit 8 lines
use kotlin

build_kotlin(
    "hello",
    list("com.google.code.gson:gson:2.14.0"),
    list(maven_central()),
    main_class = "MainKt",
)

xkit run downloads the JDK, Kotlin and Gson, builds the jar and starts it.

project.build · functions, conditions, plugins 23 lines
use kotlin
use go

repositories = list(maven_central())
jdk = if env("CI", default = "false") == "true" { "17" } else { "21" }

// what every service shares, in one place
service = fn (name: str, dependencies: list<str | module> = list()) -> module {
    build_kotlin(
        name,
        dependencies,
        repositories,
        main_class = "MainKt",
        jdk = jdk,
        directory = name,
    )
}

core = service("core")
api = service("api", list(core, "com.google.code.gson:gson:2.15.0"))

// a Go program for the servers, from the official plugin
build_go("gateway", goos = "linux", goarch = "arm64", directory = "gateway")
  • Functions with typed parameters and defaults. What every module shares is written once.
  • Conditions are values. The block that runs is the result, like the JDK of a CI build.
  • Strings as types. "auto" | "local" takes exactly those two, a typo names the nearest one.
  • Plugins are build scripts too. The Go support is a 66-line build script (opens in a new tab) that downloads Go and runs it. Write your own →
  • No loops.
    No IO.
    No HTTP.
  • On purpose: building has to be simple and reproducible.

03 / How it works

From script
to artifact.

build reads the script, resolves what its modules need, compiles every language with its own compiler and builds modules that do not depend on each other at the same time. A module whose inputs did not change is up to date and does not build again.

The pipeline of xkit: project.build and project.lock, then Maven repositories, vcpkg ports, plugins, JDKs and tools, then kotlinc and javac, aapt2 and d8, clang and go build, then jars, apks, libraries and programs. project.build modules, their calls project.lock checksums, commits Maven repositories POMs, BOMs, variants vcpkg ports C and C++ libraries plugins tags in git JDKs and tools checked by SHA-256 kotlinc + javac Kotlin and Java aapt2 + d8 Android apps clang, cc C and C++ sources go build a build_command api.jar build/libs/ app-debug.apk build/outputs/apk/ libpricing.a build/lib/ gateway build/commands/ 01 / MANIFEST 02 / RESOLUTION 03 / COMPILATION 04 / ARTIFACTS The pipeline of xkit: project.build and project.lock, then Maven repositories, vcpkg ports, plugins, JDKs and tools, then kotlinc and javac, aapt2 and d8, clang and go build, then jars, apks, libraries and programs. project.build modules, their calls project.lock checksums, commits Maven repositories POMs, BOMs, variants vcpkg ports C and C++ libraries plugins tags in git JDKs and tools checked by SHA-256 kotlinc + javac Kotlin and Java aapt2 + d8 Android apps clang, cc C and C++ sources go build a build_command api.jar build/libs/ app-debug.apk build/outputs/apk/ libpricing.a build/lib/ gateway build/commands/ 01 / MANIFEST 02 / RESOLUTION 03 / COMPILATION 04 / ARTIFACTS

Every module keeps a fingerprint of its inputs in build/fingerprints/ · nothing changed: [api] Up to date

04 / Quickstart

Three commands.

Once build is installed, a Kotlin program is three commands away. The JDK and the Kotlin compiler come with the first build.

  1. Create a project

    xkit new kotlin hello
    Created kotlin project hello in hello with the package com.example.hello
  2. Build it

    cd hello && xkit
    [hello] JDK ~/.xkit/jdks/temurin-21-macos-aarch64/Contents/Home[hello] Resolving dependencies (Kotlin 2.4.21)[hello] Compiling 1 Kotlin file(s)[hello] Done: ~/hello/./build/libs/hello.jar
  3. Run it

    xkit run
    [hello] Up to date> Running helloHello from hello