Taxi CLI

Kotlin Plugin

Overview

The Kotlin Plugin generates Kotlin classes, annotated with @DataType. This makes referencing taxi types in services more typesafe and robust.

While this plugin generates Kotlin code, the generated code is designed to be usable in both Kotlin and Java projects without requiring a Kotlin runtime dependency.

Enable the plugin by configuring the plugins section of your taxi.conf file:

name: com.petflix/films
version: 0.1.0
sourceRoot: src/
plugins: {
   taxi/kotlin: {
     ## Other config goes here if required (see below)
   }
}

The plugin is then invoked when running the Taxi CLI build command:

➜  taxi build
Taxi 1.62.0 @89cba14 
Fetching dependencies for com.petflix/films/0.1.0 
Running generator @taxi/kotlin 
Generator @taxi/kotlin generated 16 files 
Wrote 16 files to /my-project/dist 

What's generated

Scalar & Primitive types

Primitive and Scalar (types without properties) are output as kotlin type alias types, with a corresponding @DataType annotation

Model types

model types in Taxi (or types that contain properties) will generate a kotlin data class. with a corresponding @DataType annotation

Enums

Enums in Taxi are output as kotlin enumclasses

Configuration

NameUsageDefault
outputPathDefines where the generated kotlin code is written. This is relative to the output parameter in the main project configkotlin
typesA list of namespaces or fully-qualified type names to generate. If empty, all types are generated. Can contain namespaces (e.g., com.foo) to generate all types within that namespace, or specific types (e.g., com.foo.Bar) to generate only that type.[] (empty - generates all types)
kotlinVersionThe version of kotlin to use. Defines the Maven dependencies that are generated2.0.20
kotlinLanguageVersionThe kotlin language version. Corresponds to the languageVersion property in Kotlin’s configuration.2.0
jvmTargetWhich version of the JVM to target.21
mavenDefines the properties used for Maven configuration. If omitted, a pom.xml file is not generated.-
taxiVersionThe version of the taxi to depend onThe same version as the compiler being used.

For more details see the KotlinPluginConfig class.

Filtering Types

You can selectively generate Kotlin code for specific namespaces or types using the types configuration option. This is useful when you only need a subset of your Taxi types in Kotlin.

Generate specific namespace

plugins: {
   taxi/kotlin: {
      types: ["com.foo"]
   }
}

This will generate Kotlin code for all types in the com.foo namespace.

Generate multiple namespaces

plugins: {
   taxi/kotlin: {
      types: ["com.foo", "com.bar"]
   }
}

Generate specific types

plugins: {
   taxi/kotlin: {
      types: ["com.foo.Person", "com.bar.Company"]
   }
}

This generates Kotlin code only for the com.foo.Person and com.bar.Company types.

Mixed filtering

You can mix namespaces and specific types:

plugins: {
   taxi/kotlin: {
      types: ["com.foo", "com.bar.Company"]
   }
}

This generates all types in com.foo namespace, plus the specific com.bar.Company type.

Generating a Maven pom.xml

The plugin will optionally generate a Maven pom.xml file, to allow you to then compile and publish a jar file containing the generated artifacts.

The plugin will generate a valid pom.xml file, but doesn't attempt to run maven to compile the generated code. That's left to you, or your build server configuration.

The following properties can be configured, which relate to the same concepts in a maven pom.xml file:

  • groupId (defaults to the organisation name within the taxi project)
  • artifactId (defaults to the project name within the taxi project)
  • dependencies
  • repositories
  • distribution management
NameUsageDefault value
groupIdThe maven groupId in the generated outputThe groupId of the taxi project
artifactIdThe maven artifactId in the generated outputThe project name of the taxi project
dependenciesConfigures additional maven dependencies in the output maven pom. Generally, this isn’t required. Kotlin and Taxi dependencies are included by defaultKotlin and Taxi dependencies
repositoriesConfigures additional repositories to download dependencies from. Use this if you have an internal maven repository server that operates as a corporate proxy to Maven centralOmitted
distributionManagementDefines where generated jar files are published using mavens deploy commandOmitted

Sample Configuration

name: taxi/maven-sample
version: 0.3.0
sourceRoot: src/
plugins: {
   taxi/kotlin: {
      maven: {
         groupId: "lang.taxi"
         artifactId: "parent"
         repositories: [
            {
               id: "internal-repo"
               url: "https://newcorp.nexus.com"
               snapshots: true
            }
         ]
         distributionManagement: {
            id: "some-internal-repo"
            url: "https://our-internal-repo"
         }
      }
   }
}

Using the Generated Code

The Kotlin plugin generates code that can be consumed in both Kotlin and Java projects, enabling teams to create a shareable taxonomy of types that can be published and consumed across microservices.

TypeNames Object

The generator creates a TypeNames object containing static constants for all type names. This provides Java-friendly interoperability while maintaining type safety.

For example, given this Taxi schema:

namespace films

[[ The Id of a film ]]
type FilmId inherits Int

[[ The title of the film ]]
type Title inherits String

The generator produces:

object TypeNames {
  object films {
    const val FilmId: String = "films.FilmId"

    const val Title: String = "films.Title"
  }
}

Usage in Java

In Java, use the TypeNames constants to annotate fields and parameters with semantic metadata:

@Service("JavaService")
public class JavaServiceTest {

   @Operation
   public Film findById(
      @DataType(value = TypeNames.films.FilmId, imported = true) String filmId
   ) {
      // implementation
   }
}

This pattern allows teams to create a shareable taxonomy of core scalars, generate the Kotlin/Java code, and consume it within their microservices.

Usage in Kotlin

For Kotlin, it’s even simpler. The code generator creates type aliases with @DataType annotations:

@DataType(
  value = FilmId,
  imported = true
)
typealias FilmId = Int

So the same service in Kotlin looks like:

@Service("KotlinService")
class KotlinServiceTest {

   @Operation
   fun findById(filmId: FilmId): Film {
      // implementation
   }
}

Integration with Other Tools

The generated code is designed to work seamlessly with:

  • java2taxi - Generates Taxi schemas from Java/Kotlin code
  • Orbital’s Spring Boot schema publisher starter - Automatically publishes schemas from Spring Boot applications
  • Other Taxi ecosystem tooling

This enables a workflow where teams can define core types in Taxi, generate code for use in services, and have tooling automatically discover and publish the semantic metadata.

Previous
Generating OpenAPI
Next
Linter